Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Tree Map Question

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have 3 objects that I want to store in a TreeMap

customerDetails
accountOne
accountTwo

Each object has the same customerID

Could I store all three objects in a Treemap using the customerID as a key or will the values be overwitten?

Simply put
How do I store these three objects in a Treemap?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If same key is used, the previous object value will be overwritten.

For example


Joyce
[ September 06, 2004: Message edited by: Joyce Lee ]
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve,

Perhaps if you could give a little background as to why you want to store objects of these different types in the same collection then someone could propose a solution. I'm not sure that what you're asking about is the best option for you.

Jules
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I don't think you can add multiple values for a single key in a TreeMap. But i think you can add the values in LinkedList or a Vector and then you can map it with the key in a TreeMap.

Hope it helps you

 
Steve Durber
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies people
The reason I have to do it this way is because its an assignment.
I have to use Treemap to hold the data that is contained in upto two accounts and the customer details.

Now the customer has a customer ID and the accounts have different numbers too. My first thought was to have a Treemap to hold the customer details, inside the customer details would be two variables that hold the unique account IDs.
I would then use a second TreeMap to hold all the account details using their uniqueIDs as the TreeMap key.

One complication, (well its complicated to me) the accounts have a different number of parameters.
[ September 06, 2004: Message edited by: Steve Durber ]
 
I'm full of tinier men! And a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic