File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes ArrayList to HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "ArrayList to HashMap" Watch "ArrayList to HashMap" New topic
Author

ArrayList to HashMap

S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 241
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: 32649
    
    4
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: 19216

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList to HashMap
 
Similar Threads
Conceptual Misunderstanding of Arraylists?
Populating a html select tag without scripting
Can I have a list in tree map?
One of My Favorite Stripes Features (A Complex Example)
Map instantiate with key-value