Skip to content

Convert LinkedHashMap to List Java Example

This example shows how to convert LinkedHashMap to a List (ArrayList, LinkedList) in Java. This example also shows how to convert map keys, values, or entries to a List.

How to convert LinkedHashMap to List in Java (ArrayList or LinkedList)?

The LinkedHashMap is an implementation of a Map. The Map and List are two different data structures. The Map stores key-value pairs while the List is an ordered collection of elements.

How to convert all keys of LinkedHashMap to a List?

You can convert all keys of the map object to a List using the keySet method as given below. The keySet method returns a Set view of all keys contained in the map object.

Output

How to convert all map values to a List?

You can convert all values of the LinkedHashMap to a List using the values method. The values method of the LinkedHashMap class returns a Collection view of all the values contained in the map object. You can then use this collection to convert it to a List object.

Output

How to convert all map entries to a List?

You can also convert all the entries (i.e. key-value pairs or mappings) to a List using the entrySet method. The entrySet method returns a Set view of all the entries contained in the LinkedHashMap object.

Output

This example is a part of the LinkedHashMap in Java Tutorial.

Please let me know your views in the comments section below.

References:
Java 8 LinkedHashMap

About the author

We are on YouTube!

Leave a Reply

Your email address will not be published.