Convert a Map to an Array, List or Set in Java
Last modified: April 8, 2017
I just announced the new Spring 5 modules in REST With Spring:
1. Overview
This short article will show how to convert the values of a Map to an Array, a List or a Set using plain Java as well as a quick Guava based example.
This article is part of the âJava â Back to Basicâ series here on Baeldung.
2. Map values to Array
First, letâs look at converting the values of the Map into an array, using plain java:
3. Map values to List
Next, letâs convert the values of a Map to a List â using plain Java:
And using Guava:
4. Map values to Set
Finally, letâs convert the values of the Map to a Set, using plain java:
5. Conclusion
As you can see, all conversions can be done with a single line, using only the Java standard collections library.
The implementation of all these examples and code snippets can be found over on GitHub project â this is a Maven-based project, so it should be easy to import and run as it is.