Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (4k points)

What is the best way to change a Map<key, value> to a List<value>? Just iterate over every value and insert them in a list or am I overlooking something?

1 Answer

0 votes
by (46k points)

The problem here is that Map has two values (a key and value), while a List only has one value (an element).

Hence, the best that can be done is to either get a List of the keys or the values:

List<Value> list = new ArrayList<Value>(map.values());

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...