Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

create a list of key/value pairs

 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. You can iterate over the map and insert them into the list.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The entrySet() method of the Map interface should be of help.
 
Campbell Ritchie
Marshal
Posts: 52575
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!