• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need collection

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any collection available in which we can store same key with different value. So that if i gave the key to get then it must provide a set or anything like that of all values?
I can understand in any collection key cannot be duplicate but is there any way to attain my spec..
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your values can always be a collection right?
HashMap<String,List<String>>
Of course you will need to subclass it to tweak the getter and setter methods
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You can stored another collection into your collections

Eg if HashMap is your main collection

And keys are 1,2,3
And you can stored sets {1,2,3} , {A,B,C} , {O} for each key

1 -> {1,2,3}
2 -> {A,B,C}
3 -> {O}

No duplicate keys and with each unique key you get a set .
Hope this helps.


 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
read this thread .it help you
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:e.g. something like HashMap<String,List><String>>


Seems Maneesh forgot to disable the HTML
It should be something like this.

Map<String, List<String>> myMap;
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Devaka Cooray wrote:
Seems Maneesh forgot to disable the HTML


You got me there!
Thanks, I have edited my post.
 
Marshal
Posts: 79176
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Devaka Cooray wrote: . . . Seems Maneesh forgot to disable the HTML

There seems to be a fault in the forum software which can change < to >< Is that how you prevent that fault? I usually write &lt; to prevent it.
 
Arvind Subramanian
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So is there is no collection already available in java to perform these operation especially tweeked set and get method coresponding to my scenario?
 
Campbell Ritchie
Marshal
Posts: 79176
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked in Apache commons or Google collections? Otherwise you will have to write your own.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arvind Subramanian wrote:So is there is no collection already available in java to perform these operation espec tweeked set and get method corespon to my scenario?


Please use real words instead of espec, corespon. Also please do take out time to proof read your post before submitting.

Coming back to your question, the answer is no.
But coming up with your own custom collection is not that difficult really. Why dont you give it a try? If you get stuck, you can always show us your code, tell us about your problem and we can help you point in the right direction? If nothing else, it will be a good learning experience.
Best of luck
 
Arvind Subramanian
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maneesh i have edited that short words.
I already had coded the custom collection, but after coding only this doubt arised.

Anyway thanks for Campbell , i didnt know about these libraries. But i found Google collection is not in stable stage, so waiting for them.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic