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..)

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.

commented: thx! +2

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.