This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Help with Data Structures... 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 "Help with Data Structures..." Watch "Help with Data Structures..." New topic
Author

Help with Data Structures...

Sneha Kashyap
Greenhorn

Joined: May 06, 2009
Posts: 22
Hi,

I am unable to decide as to which data structure to use for the following purpose
Slno Name
01 abc
01 def
02 abc
03 xyz

I want these to be grouped and then stored accordingly Like: 01 {abc,def}
02 {abc}
03 {xyz}
I want to group these as itemsets based on the sl no value.

Please Help Thanks in advance.
mahesh shinde
Ranch Hand

Joined: Jul 24, 2009
Posts: 69

you mean which collection class
Sneha Kashyap
Greenhorn

Joined: May 06, 2009
Posts: 22
Thanks, Yeah and how to use it to achieve the same.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41144
    
  45
How about Map<Integer, List<String>>?

Or maybe Map<String, List<String>> if the "01" is a string and not an integer.


Ping & DNS - my free Android networking tools app
Sneha Kashyap
Greenhorn

Joined: May 06, 2009
Posts: 22
Thanks, but map cannot contain duplicate values, I need to have duplicate keys, like 01 mapping to abc,def Can you help me as to how this can be achieved.
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
i guess it is TreeSet which will eliminate the duplicate not the HashMap.
name-value pairs are sufficient.
don't confuse with HashSet and HashMap.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41144
    
  45
Thanks, but map cannot contain duplicate values, I need to have duplicate keys, like 01 mapping to abc,def

That's not duplicate keys in the Map, that's multiple entries in the List.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38046
    
  22
Sneha Kashyap wrote: Thanks, but map cannot contain duplicate values, I need to have duplicate keys, like 01 mapping to abc,def Can you help me as to how this can be achieved.
Ulf has already told you what to do.
 
jQuery in Action, 2nd edition
 
subject: Help with Data Structures...
 
Similar Threads
String array to arraylist
Collection in java
Concurrent Modifiaction Exception
Collection to read data from a file and store it in memory???
String.split("").......Confusion.