This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes ArrayList to HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ArrayList to HashMap" Watch "ArrayList to HashMap" New topic
Author

ArrayList to HashMap

S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Hi everybody ,
Is there any java methods available by which I can take the ArrayList values and put into the HashMap's key or value ?

I am giving one example here :



I know I can do it by iterating the myList into loop & get those values & put into myMap.

Thanks

S
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
It is quite easy to put keys or values into a Map, but you need to put them in pairs. If your elements from the Map go as Keys, what would you use as Values? If your elements from the Map go as Values, what would you use as Keys?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

Nope, that's the only one. The reason is the completely different structure of List (and Set, Collection, Queue, etc - all flat sequence structures) versus Map (key-to-value mapping).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList to HashMap