*
The moose likes Java in General and the fly likes create a list of key/value pairs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "create a list of key/value pairs" Watch "create a list of key/value pairs" New topic
Author

create a list of key/value pairs

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303
I am not sure if the following is doable:

I have say a hashmap - key:"1" value: "one".

I want to convert this hashmap to a list - ["1":"one"]

Is this doable?


SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
Yes. You can iterate over the map and insert them into the list.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

The entrySet() method of the Map interface should be of help.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37907
    
  22
Do you really want a List? There is no particular order to the entries in a Map. You can use a hybrid list and Map of you wish to introduce an ordering.
 
Don't get me started about those stupid light bulbs.
 
subject: create a list of key/value pairs
 
Similar Threads
I want to check previous (value) of HashMap before adding the current key?
HashSet question
Records in Arraylist
Sorting Keys(Value Objects) in HashMap
Convert List to a Map