I need to implement some kind table-like data structure that stores info like this in Java:
+--------+-------+-----+ | sij | i | j | +--------+-------+-----+ | 45 | 5 | 7 | +--------+-------+-----+ | 33 | 1 | 6 | +--------+-------+-----+ | 31 | 0 | 9 | +--------+-------+-----+ | 12 | 8 | 2 | +--------+-------+-----+
and I have to be able to sort the table by the sij
parameter. I've made some tests with ArrayList
and HashMap
, but I can't make them work well.
Table is a data structure which plays a significant role in information retrieval. A set of n distinct records with keys K1, K2, …., Kn are stored in a file. If we want to find a record with a given key value, K, simply access the index given by its key k. The table lookup has a running time of O(1).
Guava's Table is a collection that represents a table like structure containing rows, columns and the associated cell values. The row and the column act as an ordered pair of keys. The row and column act as an ordered pair of keys.
Java provides a useful class called JTable that enables you to create tables when developing graphical user interfaces using the components of Java's Swing API. You can enable your users to edit the data or just view it.
Types of Data Structures in JavaStack. Queue. Binary Tree. Binary Search Tree.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With