wood burning stoves*
The moose likes Java in General and the fly likes How to link Hashmap and Arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to link Hashmap and Arraylist" Watch "How to link Hashmap and Arraylist" New topic

How to link Hashmap and Arraylist

Ayan Biswas
Ranch Hand

Joined: Jul 10, 2010
Posts: 104
I need to create a link between hashmap and arraylists such that with every hashmap entry there will be an arraylist linked to it.How can I do it?

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11161

well...this is just my opinion, but I'd say you need to re-think your design.

Maintaining data in two parallel data structures is almost always the wrong way to do it.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ayan Biswas
Ranch Hand

Joined: Jul 10, 2010
Posts: 104
@fred rosenberger actually I need to create an indexing system where I need to read terms from a collection of files and store the word ,frequencies and the list of files(file ids).So, what I thought about storing the word,frequency in the hashmap and the file-ids in the arraylist where the words appear.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

I can't claim to understand precisely what data you are working with here, but what you most likely need to do is define a class to hold all the information associated with a key, and then put the data into instances of that class and store them in the map as the values. Your class might (for example) contain an ArrayList as a member.

[Jess in Action][AskingGoodQuestions]
Ayan Biswas
Ranch Hand

Joined: Jul 10, 2010
Posts: 104
@Ernest Friedman-Hill thanks..got it..
I agree. Here's the link: http://aspose.com/file-tools
subject: How to link Hashmap and Arraylist
Similar Threads
struts 2 s:radio tag
Interview Question & help in Vector,HashMap & ArrayList
Any Link Between ArrayList and HashMap
Difference between HashMap and arraylist
How to print the elements of an arraylist that contains a hashmap