• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a TreeMap with duplicate key values

 
David Laverdy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



The output is
555
444
333
444
555

How do I go about in the right direction getting the proper output for each Key ?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12084
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are more likely to get the help you need if you post code that compiles. I got 4 errors when I tried compiling this.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Laverdy wrote:How do I go about in the right direction getting the proper output for each Key ?


Impossible to say, since you haven't stated what you expect the output to be, or what the rules are you want to follow to produce that output, what it means to have "aaa" associated with both "111" and "555".

Note, though, that a Map by definition allows only one value per key.

The most common approach to what you seem to be asking would be to create a Map<String, List<String>>, but until you TellTheDetails(←click), that's just a guess.

 
David Laverdy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for being a little vague, new to posting here. The output I should expect is
aaa has the values 111 555
bbb has the values 222 444
ccc has the value 333
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then, yes, Map<String, List<String>> is the way to go, at least for a first pass.

Is there any particular reason you're using Strings "111", "222", etc., rather than ints 111, 222? Or are those just examples to distinguish keys from values?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic