• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tree Map Question  RSS feed

 
Steve Durber
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?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
Joyce Lee
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 ]
 
Julian Kennedy
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
 
yacoob ali
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!