int[] (int[] needed, int[] toDiscard, int arrayIndex) { myOriginalLengths[arrayIndex] = toDiscard.length; int[] sorted1 = createSorted(needed); IntList discarded = new IntArrayList(toDiscard.length); IntList oldIndices = new IntArrayList(toDiscard.length); for (int i = 0; i < toDiscard.length; i++) { int index = toDiscard[i]; if (Arrays.binarySearch(sorted1, index) >= 0) { discarded.add(index); oldIndices.add(i); } } myOldIndices[arrayIndex] = oldIndices.toIntArray(); myDiscardedLengths[arrayIndex] = discarded.size(); return discarded.toIntArray(); }