0 votes
1 view
in Java by (4.1k 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 (46.1k 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

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 10, 2019 in Java by Ritik (3.5k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...