Используйте следующий код для удаления определенной строки из массива 2d
import java.util.ArrayList;
import java.util.List;
public class RemoveRowFrom2dArray
{
private double[][] data;
public RemoveRowFrom2dArray(double[][] data)
{
int r= data.length;
int c= data[0].length;
System.out.println("....r...."+r+"....c...."+c);
this.data= new double[r][c];
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
this.data[i][j] = data[i][j];
}
}
}
/* convenience method for getting a
string representation of matrix */
public String toString()
{
StringBuilder sb = new StringBuilder(1024);
for(double[] row : this.data)
{
for(double val : row)
{
sb.append(val);
sb.append(" ");
}
sb.append("\n");
}
return(sb.toString());
}
public void removeRowsWithRowNumber(double rowNotToBeAdd)
{
List<double[]> rowsToKeep = new ArrayList<double[]>(this.data.length);
for( int i =0; i<this.data.length; i++){
if(i!=rowNotToBeAdd){
double[] row = this.data[i];
rowsToKeep.add(row);
}
}
this.data = new double[rowsToKeep.size()][];
for(int i=0; i < rowsToKeep.size(); i++)
{
this.data[i] = rowsToKeep.get(i);
}
}
public static void main(String[] args)
{
double[][] test = { {1, 2, 3, 4, 5, 6, 7, 8, 9},
{6, 2, 7, 2, 9, 6, 8, 10, 5},
{2, 6, 4, 7, 8, 4, 3, 2, 5},
{9, 8, 7, 5, 9, 7, 4, 1, 10},
{5, 3, 6, 8, 2, 7, 3, 7, 2} };
//make the original array and print it out
RemoveRowFrom2dArray m = new RemoveRowFrom2dArray(test);
System.out.println(m);
//remove rows with trow number 4 from the 2d array
m.removeRowsWithRowNumber(4);
System.out.println(m);
}
}