I'm fairly new in Java, and I'm making a structure for wrapping this kind of data:
Object:
name:'Obj1'
otherAttr:'...'
Object:
name:'Obj2'
otherAttr:'...'
Object:
...
I know that I can make my custom 'Object' class*, but for using builtin java structures I use List<Map<String, String>>
. So, for setting new one:
List<Map<String, String>> objects = new ArrayList<Map<String, String>>();
foreach(databaseRow){
Map<String, String> newObject = new HashMap<String, String>();
newObject.put('name', '...');
newObject.put('otherAttr', '...');
objects.add(newObject);
}
I have two questions:
1- If the initializations of the structures (as an ArrayList
and as an HashMap
) are the best choises between the huge amount of Java structures.
2- If there is a builtin structure that doesen't implies all those initializations (for the List and for each Map).
Thank you!
(*)CLARIFICATION: I use plenty of structures similar of that in my code, and I would avoid to make a lot of custom classes. But if it's the best way, let's do it!