Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList to HashMap  RSS feed

 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53742
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!