Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
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

Browse Categories