If you need fast random access, you can use HashMap with cell keys.
public class CellKey {
final String col;
final String row;
private CellKey () {} // no instatiation outside
public CellKey at(String row, String column) {
this.col = column;
this.row = row;
}
public getColumn() {
return col;
}
public getRow() {
return row;
}
public int hashCode() {
return Objects.hash(col, row);
}
public boolean equals(CellKey other) {
return this.col.equals(other.col) && this.row.equals(other.row);
}
}
Now use it in collection representing cell values:
Map<CellKey, List<Integer>> cells = new HashMap<>();
// get value
cells.get(CellKey.at(row, column));
// put value
cells.put(CellKey.at(row, column), value);
cells.put(CellKey.at(row, column), Arrays.asList(int1, int2, int3));
// check if value exists
cells.contains(CellKey.at(row, column));
// iterate over all cells containing values
cells.entrySet().stream().forEach(e -> {
String row = e.getKey().getRow();
String column = e.getKey().getColumn();
List<Integer> value = e.getValue();
// make your actions
});
// iterate over given row
String row = "K";
String[] columns = new String[]{"A", "B", "C", "D"};
for (String c : columns) {
List<Integer> values = cells.get(CellKey.at(row, c));
// perform actions
}