0

I have this simple problem which I cannot solve.

I have this Map which stores the sessions:

Map<String, ActiveConnections>

I want to get all String values and insert them into ArrayList.

Can you tell em how I can do this?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

2 Answers2

5

You can get all the keys using the keySet() method and create a new ArrayList with that.

List<String> list = new ArrayList<String>(map.keySet());
Rahul
  • 44,383
  • 11
  • 84
  • 103
2

Map contains a method called keySet() , Which

Returns a Set view of the keys contained in this map.

Then use that Set to build your List, by using constructor or using addAll method

keyList.addAll(set);
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307