• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to link Hashmap and Arraylist

 
Ayan Biswas
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ayan Biswas
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ayan Biswas
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ernest Friedman-Hill thanks..got it..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic