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..)
anilopo 0
Light Poster
Recommended Answers
Jump to PostI 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.
All 2 Replies
JamesCherrill 4,733
Most Valuable Poster Team Colleague Featured Poster
anilopo
commented:
thx! +2
anilopo 0
Light Poster
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.