I need to implement some kind table-like data structure that stores info like this in Java:
+--------+-------+-----+
| sij | i | j |
+--------+-----
There is a generic TreeBasedTable class from Google guava library which does exactly what you are asking for. It also offers many other useful utility methods and its usage is shown in the user guide.
From the TreeBasedTable
docs:
Implementation of Table whose row keys and column keys are ordered by their natural ordering or by supplied comparators.
Example usage:
RowSortedTable<Vertex, Vertex, Double> weightedGraph = TreeBasedTable.create();
weightedGraph.put(v2, v3, 4.0);
weightedGraph.put(v1, v2, 20.0);
System.out.println( weightedGraph.rowKeySet() ); // prints [v1, v2]