Here you can find the source of removeRows(int[][] array, Collection
Parameter | Description |
---|---|
array | The array |
rowsIndices | The rows to be removed |
public static int[][] removeRows(int[][] array, Collection<Integer> rowsIndices)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.Collections; public class Main { /**//from w ww .ja v a 2 s .c o m * @brief Returns a copy of a given array with the specified rows removed * * @param array * The array * @param rowsIndices * The rows to be removed * * @return A copy of the given array with the specified rows removed */ public static int[][] removeRows(int[][] array, Collection<Integer> rowsIndices) { int newLength = array.length - rowsIndices.size(); int[][] newArray = new int[newLength][]; ArrayList<Integer> listOfRows = new ArrayList<Integer>(rowsIndices); Collections.sort(listOfRows); int currentRowInNewArray = 0; int currentIndexInArray = 0; for (int i = 0; i < array.length; i++) { if (currentIndexInArray < listOfRows.size() && i == listOfRows.get(currentIndexInArray)) { currentIndexInArray++; continue; } newArray[currentRowInNewArray] = array[i]; currentRowInNewArray++; } return newArray; } }