Table like java data structure

前端 未结 7 1754
星月不相逢
星月不相逢 2020-12-03 01:14

I need to implement some kind table-like data structure that stores info like this in Java:

+--------+-------+-----+
|  sij   |   i   |  j  |
+--------+-----         


        
相关标签:
7条回答
  • 2020-12-03 01:54

    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]
    
    0 讨论(0)
提交回复
热议问题