Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic table / matrix data structure for Java

Tags:

I need a Java implementation of table-like data structure where I could dynamically insert or delete rows and columns. I need to get data from any row or column very fast and with no overhead in selecting row over column or vice versa.

Does anyone know libraries where such data structure is already implemented?

like image 211
Alexander Temerev Avatar asked Feb 11 '10 18:02

Alexander Temerev


People also ask

What is dynamic data structure in Java?

In Dynamic data structure, the size of the structure is not fixed and can be modified during the operations performed on it. Dynamic data structures are designed to facilitate change of data structures in the run time.

Which data structure is best for Matrix?

For a sparse array, a HashMap is an excellent choice. It's relatively fast - O(1) lookup - and relatively space efficient. I say relatively because there are many overheads. There are other Map implementations that have different behaviour - for example a TreeMap performs in O(lg n) but is sorted by key.

Is stack a dynamic data structure?

Stacks are dynamic data structures that follow the Last In First Out (LIFO) principle. The last item to be inserted into a stack is the first one to be deleted from it.

What is static data and dynamic data in Java?

Static Data structure has fixed memory size whereas in Dynamic Data Structure, the size can be randomly updated during run time which may be considered efficient with respect to memory complexity of the code. Static Data Structure provides more easier access to elements with respect to dynamic data structure.


2 Answers

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

like image 132
camickr Avatar answered Oct 03 '22 19:10

camickr


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

like image 24
Eli Acherkan Avatar answered Oct 03 '22 18:10

Eli Acherkan