-4

enter image description here

how to declare variable like this-- ArrayList LinkedhashMap.

Derek
  • 1,177
  • 3
  • 11
  • 26

2 Answers2

2
Map<String, ArrayList<LinkedHashMap<KeyType, ValueType>> maps;

KeyType and ValueType are placeholders, I don't know the real types. And the real declaration should use interfaces. But that's the closest to answer your question.

(The better declaration:

Map<String, List<Map<KeyType, ValueType>> maps;

We map lists of maps to string values. That's the explanation for this datastructure )

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
2

Well if you are using Java 1.5 or greater , you can make use of Generics

//This approach is type safe.
List<LinkedHashMap<KeyType,ValueType>> myListOfMaps  = ArrayList<LinkedHashMap<KeyType, ValueType>>();

for Java less that 1.5 use normal Arraylist.

List myListOfMaps  = new ArrayList (); //But with this approach its not type safe , 
                                    //because any object type can be inserted

Now to create a Map of ListsofMaps

Map<String, List<Map<KeyType, ValueType>> maps = new HashMap <String, List<Map<KeyType, ValueType>>();
maps.put("rows",myListOfMaps  );

This link will give you Why Use Generics ?

Check this Generic tutorial for more info

Sudhakar
  • 4,823
  • 2
  • 35
  • 42