How to Convert Map to List in Java?

We can Convert Map to List in java using the Map.keySet and Map.values method. The Map contains the value in the key value pair while on the other hand list contain only value. So keys as a List can be obtained by creating a new ArrayList from a Set returned by the Map.keySet method. while the values as a List can be obtained creating a new ArrayList from a Collection returned by the Map.values method.

Example to convert map to list in java:-

output:-

Leave a Reply

Your email address will not be published. Required fields are marked *