Joseph
Joseph

Reputation: 1

create an ArrayList, with a hashmap in each value

I am looking to create an arraylist, with a hashmap in each value. Not sure how to even start this? Anybody have some old code, or can help out?

Upvotes: 0

Views: 39

Answers (2)

Dan Ciborowski - MSFT
Dan Ciborowski - MSFT

Reputation: 7207

In Java

ArrayList<Map<Integer, String>> list = new Arraylist<>();
list.add(new HashMap<Integer, String>());
list.get(0).put(1, "Value");

Upvotes: 1

David Newcomb
David Newcomb

Reputation: 10943

With generic in Java:

ArrayList<HashMap<Integer,String>> david = new ArrayList<HashMap<Integer,String>>();
david.add(new HashMap<Integer,String>());

Upvotes: 0

Related Questions