how to convert map to list in java?

5.01K viewsJava
0

Best way to convert Map values to List in Java, please suggest to me.

Manohar Changed status to publish July 21, 2019
Add a Comment
2
Raju (anonymous) 0 Comments

Hi,

In Java JDK 1.8 :

List<String> listValues = map.values().stream().collect(Collectors.toList());

Manohar Changed status to publish June 26, 2019
Add a Comment
0

Use below snippet code, it will work fine, try and let us know.

 

//here am creating map values and putting some values
Map<String, String> map= new HashMap<String, String>();
map.put("P", "Programming");
map.put("B", "Business");
map.put("T", "Technology");

//here am iterating the map and putting in to list
List<String> listVal = new ArrayList(map.values());

 

Manohar Changed status to publish June 26, 2019
Add a Comment
Write your answer.