Home > Java, Programación, Tips > Remover una fila/row de un arreglo bidimensional Java

Remover una fila/row de un arreglo bidimensional Java

public String[][] removeRowFrom2dArray(String[][] array, int row){
    int rows = array.length;
    String[][] arrayToReturn = new String[rows-1][];
    for(int i = 0; i < row; i++)
        arrayToReturn[i] = array[i];
    for(int i = row; i < arrayToReturn.length; i++)
        arrayToReturn[i++] = array[i];
    return arrayToReturn;
}

O también puede ser:

public String[][] removeRowFrom2dArray(String[][] array, int row){
    List list = Arrays.asList(array);
    list.remove(row);
    return list.toArray(new String[][]{});
}

Categories: Java, Programación, Tips
  1. June 14, 2011 at 17:14

    En el primer ejemplo quitaría la parte de cols ya que no es necesario.

  2. June 17, 2011 at 10:35

    Tienes razón arthur, fixed, thx!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: