Source:
public ReadCountCollection subsetColumns(final Set<String> columnsToKeep) { Utils.nonNull(columnsToKeep, "the input columns to keep set cannot be null"); if (columnsToKeep.isEmpty()) { throw new IllegalArgumentException("the number of columns to keep must be greater than 0"); } if (columnsToKeep.size() == columnNames.size()) { if (columnNames.stream().anyMatch(name -> !columnsToKeep.contains(name))) { throw unknownColumnToKeepNames(columnsToKeep); } else { return new ReadCountCollection(targets, columnNames, counts.copy()); } } else if (columnsToKeep.size() > columnNames.size()) { throw unknownColumnToKeepNames(columnsToKeep); } final int[] columnsToKeepIndices = new int[columnsToKeep.size()]; int nextIndex = 0; final List<String> resultColumnNames = new ArrayList<>(columnsToKeep.size()); for (int i = 0; i < columnNames.size(); i++) { final String column = columnNames.get(i); if (!columnsToKeep.contains(column)) { continue; } else if (nextIndex >= columnsToKeepIndices.length) { throw unknownColumnToKeepNames(columnsToKeep); } else { columnsToKeepIndices[nextIndex++] = i; resultColumnNames.add(column); } } if (nextIndex < columnsToKeep.size()) { throw unknownColumnToKeepNames(columnsToKeep); } final double[][] resultCounts = new double[counts.getRowDimension()][columnsToKeepIndices.length]; for (int i = 0; i < resultCounts.length; i++) { final double[] rowCounts = counts.getRow(i); for (int j = 0; j < columnsToKeepIndices.length; j++) { resultCounts[i][j] = rowCounts[columnsToKeepIndices[j]]; } } return new ReadCountCollection(targets, Collections.unmodifiableList(resultColumnNames), new Array2DRowRealMatrix(resultCounts, false)); }

Target:
public ReadCountCollection subsetColumns(final Set<String> columnsToKeep) { Utils.nonNull(columnsToKeep, "the set of input columns to keep cannot be null."); if (columnsToKeep.isEmpty()) { throw new IllegalArgumentException("the number of columns to keep must be greater than 0"); } if (columnsToKeep.size() > columnNames.size()) { throw unknownColumnToKeepNames(columnsToKeep); } if (columnsToKeep.size() == columnNames.size()) { if (columnNames.stream().anyMatch(name -> !columnsToKeep.contains(name))) { throw unknownColumnToKeepNames(columnsToKeep); } else { return new ReadCountCollection(targets, columnNames, counts.copy()); } } final int[] columnsToKeepIndices = new int[columnsToKeep.size()]; int nextIndex = 0; final List<String> resultColumnNames = new ArrayList<>(columnsToKeep.size()); for (int i = 0; i < columnNames.size(); i++) { final String column = columnNames.get(i); if (!columnsToKeep.contains(column)) { continue; } if (nextIndex >= columnsToKeepIndices.length) { throw unknownColumnToKeepNames(columnsToKeep); } else { columnsToKeepIndices[nextIndex++] = i; resultColumnNames.add(column); } } if (nextIndex < columnsToKeep.size()) { throw unknownColumnToKeepNames(columnsToKeep); } final double[][] resultCounts = new double[counts.getRowDimension()][columnsToKeepIndices.length]; for (int i = 0; i < resultCounts.length; i++) { final double[] rowCounts = counts.getRow(i); for (int j = 0; j < columnsToKeepIndices.length; j++) { resultCounts[i][j] = rowCounts[columnsToKeepIndices[j]]; } } return new ReadCountCollection(targets, Collections.unmodifiableList(resultColumnNames), new Array2DRowRealMatrix(resultCounts, false)); }