
-----------------------------------
Pockets
Mon Nov 10, 2008 2:05 am

Map -&gt; Arraylist
-----------------------------------
Is there a method out there to strip out the keys to a Map and return an ArrayList of all the elements? In the context here, the keys are unimportant and can be discarded.

-----------------------------------
DemonWasp
Mon Nov 10, 2008 9:51 am

RE:Map -&gt; Arraylist
-----------------------------------
Without speaking to any kind of efficiency concern, you could use:

map.entrySet().toArray

to get an array. Array -> ArrayList is trivial too.

-----------------------------------
OneOffDriveByPoster
Mon Nov 10, 2008 10:11 am

Re: RE:Map -&gt; Arraylist
-----------------------------------
map.entrySet().toArrayThe above won't get you just the values of course.  Anyhow, why do you need the conversion?  Do you have methods you need to call that need an ArrayList?

-----------------------------------
Pockets
Mon Nov 10, 2008 4:35 pm

Re: Map -&gt; Arraylist
-----------------------------------
Yeah, it's for a game of hearts. We're handed a trick as a map of , and I need to strip the card objects into a simple array for use in a card counting function. I may just use a manual iterator though.

-----------------------------------
OneOffDriveByPoster
Mon Nov 10, 2008 4:56 pm

Re: Map -&gt; Arraylist
-----------------------------------
I may just use a manual iterator though.This is probably a cleanest thing to do.  If you are not sure you will always have a Map, then use a Iterator from Map.values().  Not sure why you wanted an ArrayList specifically.  Map.values() will give you a Collection view of the map's values.  Your algorithm might not need to have something as specific as ArrayList.
