Dynamic tabular / matrix data structure for Java

I need a Java implementation in the form of a tabular data structure, where I could dynamically insert or delete rows and columns. I need to get data from any row or column very quickly and with no overhead when selecting a row above a column or vice versa.

Does anyone know of a library where such a data structure has already been implemented?

+4
source share
5 answers

You might be able to use DefaultTableModel. It was intended for use with JTable, but there is no reason why it cannot be used alone. You will need to add methods to retrieve data for a full row or column.

+3
source

If performance is critical, you can use a 2D array and implement a redistribution algorithm (e.g. doubling) so that it can grow.

+1
source

Maybe JQL or HSQL DB

0
source

The HashBasedTable class from the Google Guava library does this. There is also a TreeBasedTable if the rows should be sorted in order.

0
source

You can simply use List<List<YourClass>> . Or even easier Map<Integer, List<YourClass>> compare the row number (first parameter, integer) with the string (second parameter, list of YourClass objects, List<YourClass> ) ... and build the DataModel class around this collection, which guarantees the possibility intersecting the same number of elements in each row (even if the row does not have all the elements, just returning zeros or empty objects or the like) by implementing a custom Iterator .

0
source

Source: https://habr.com/ru/post/1301030/


All Articles