File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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

Joined: Jan 10, 2002
Posts: 63841

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

[Asking smart questions] [About Bear] [Books by Bear]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
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.
I agree. Here's the link:
subject: create a list of key/value pairs
It's not a secret anymore!