• 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

Creating a TreeMap with duplicate key values

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic