aspose file tools*
The moose likes Beginning Java and the fly likes Hashmap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hashmap " Watch "Hashmap " New topic
Author

Hashmap

akshitha Akki
Greenhorn

Joined: Aug 03, 2012
Posts: 24
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
Sheriff

Joined: Sep 28, 2004
Posts: 19060
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
akshitha Akki
Greenhorn

Joined: Aug 03, 2012
Posts: 24
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
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hashmap