This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hashmap

 
akshitha Akki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashMap stores the contents in a key value pairs.So is it possible to store set of 'keys' in one arraylist, set of values in another arraylist and then send these arraylists to hashmap.
Gave a try to do the same. But did not get the concept of how the arraylist contents gets stored in HashMap.

Example:
Arraylist first has set of key - apple, orange, papaya
Arraylist second has set of values - red, yellow, green

so now the two arraylists have to be passed to hash map
HashMap<ArrayList, ArrayList> test = new HashMap<ArrayList, ArrayList>()

Can someone please help to get the concept of how the contents gets stored in arraylist and HashMap.
 
Henry Wong
author
Marshal
Pie
Posts: 21123
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akshitha Akki wrote:HashMap stores the contents in a key value pairs.So is it possible to store set of 'keys' in one arraylist, set of values in another arraylist and then send these arraylists to hashmap.
Gave a try to do the same. But did not get the concept of how the arraylist contents gets stored in HashMap.

Example:
Arraylist first has set of key - apple, orange, papaya
Arraylist second has set of values - red, yellow, green

so now the two arraylists have to be passed to hash map
HashMap<ArrayList, ArrayList> test = new HashMap<ArrayList, ArrayList>()

Can someone please help to get the concept of how the contents gets stored in arraylist and HashMap.


I don't think that the core library has anything that does it automatically -- but you can easily write code that loops through the arraylists to add the pairs to the hashmap.

Henry
 
akshitha Akki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I did try to do that, but i was unable to get the name from one arraylist, value from another arraylist and store them in a hashmap at the same time.Can I get a hint to get that concept so that I can do that.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really? You can't come up with any code which iterates through a list? Because that would be your first step, wouldn't it? Remember that your requirement is "Iterate through two ArrayLists and..." so iterating would be the first thing to work on.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic