A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
ArrayList to HashMap
Joined: Jun 03, 2009
Jun 02, 2011 03:22:24
Hi everybody ,
Is there any
methods available by which I can take the
values and put into the
's key or value ?
I am giving one example here :
List<Integer> myList = new ArrayList<Integer>(); myList .add(6); myList .add(7); myList .add(8); myList .add(9); Map<Integer,Integer> myMap = new HashMap<Integer,Integer>();
I know I can do it by iterating the myList into loop & get those values & put into myMap.
Joined: Oct 13, 2005
Jun 02, 2011 09:48:34
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?
Joined: Oct 27, 2005
Jun 02, 2011 10:31:51
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 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: ArrayList to HashMap
Can I have a list in tree map?
Map instantiate with key-value
One of My Favorite Stripes Features (A Complex Example)
Conceptual Misunderstanding of Arraylists?
Populating a html select tag without scripting
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015