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?
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.
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.
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.
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.
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.
If the performance is critical, you can use a 2D-array, and implement a reallocation algorithm (e.g. doubling) so that it can grow.
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