Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Column Structure Java

In C# there is DataTable type which can be used to create multi-column structures. In java I can use nested hashmaps but its too complicated structure even if you have 3 columns. Does core java support any such structure without including any external library?

I can use multidimensional arrays but still checking for any possible option.

like image 717
Pit Digger Avatar asked Oct 03 '12 20:10

Pit Digger


1 Answers

Java has no directly available table format. However, we can use the generics functionality to our advantage here. You can read about them here. Instantiation will look like this

Map<String, List<String>> tableMap = new HashMap<String, List<String>>();

Now, you have a 2D structure with an identifier String for every row, and the rest of the row stored as a list. You do need to choose unique identifiers for each row though, so if you are aiming to map it with a table (as you do in C#), make sure that the key of the HashMap is the primary key of the table.

I hope that helped.

like image 157
Achrome Avatar answered Nov 12 '22 20:11

Achrome