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
  • 2,352
  • 100
  • 358
  • 675

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
  • 43,125
  • 11
  • 82
  • 101
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
  • 118,038
  • 37
  • 189
  • 297