0

I want to pass all the values from a HashMap to ArrayList (that a demand of my exercise..) and to use for it an iterator (to the HashMap).
How do I get the first key to the HashMap?
(if I have the first I'll continue in a loop untill there is no "hasNext ()" to the iterator..)

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by anilopo
1

I want to pass all the values from a HashMap to ArrayList

HashMap has a values() method that returns a Collection of all the values.
ArrayList has a constructor that takes a Collection of values to populate the list. So all you need is a single line of code.

Votes + Comments
thx!
0

HashMap has a values() method that returns a Collection of all the values.
ArrayList has a constructor that takes a Collection of values to populate the list. So all you need is a single line of code.

I worked it out with an iterator.
but maybe I'll change it eventually..

thx!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.