Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best data structure to implement a 2D Matrix with String data type?

I have huge table data with 150 rows and 10 Columns, each column has String data. After storing the data, I have to traverse as well to find a particular value. So, I am looking for answers to the best data structure in this case in terms of performance, flexibility of traversing.

I have thought of Array, ArrayList, Hashmap.

Also, I have found similar questions on SO but they don't answer my question.

EDIT: The data is a mixture of Alphabets and Integers. Cannot be sorted and contains duplicates as well.

like image 708
Haxor Avatar asked Jan 06 '23 01:01

Haxor


1 Answers

It seems then for such table size combination 2D Array[][] + Hashmap would be an excellent choice. Simple and effective.

Array contains values and allows to traverse the table in any order.

HashMap contains pairs <String; TPoint> (coordinates in array - Row/Col pair).

If you need only to know whether the table contains some string, then don't store coordinates in Map.

I think that Guava Table proposed by @krzyk, provides similar functionality (don't know about performance)

like image 83
MBo Avatar answered Jan 08 '23 16:01

MBo