• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using TreeMap class  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I am using the TreeMap class to store objects. My method;

TreeMap map = new TreeMap();
My key is a string.

I place objects into map as follows;
map.put(new String (keyName.toLowerCase()), new testObject(str1,str2,int1,int2));

I then call the objects using;
Set keys = map.keySet();
Iterator keysIterator = keys.iterator();
while ( keysIterator.hasNext() )
{
String key = (String) keysIterator.next();
Object testObject=(((Object) map.get (key)));
}

What I'd like to then do is to be able to change the values of the object, ie str1,str2,int1,int2. I know I have to use accessor and mutator methods but I'm having extreme difficulty figuring out how to construct the syntax.

Any help will be most appreciated.
Dominique
 
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ August 25, 2004: Message edited by: Pradeep Bhat ]
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Dominique Ramoney
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep you are my hero!

You nailed it except for this line;

testObject test=(((Object) map.get (key)));

should be;

testObject test=(((testObject) map.get (key)));

Cheers
Dominique
 
Dominique Ramoney
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somkiat beat me to it.

Thanks again guys.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dominique Ramoney:
Pradeep you are my hero!

You nailed it except for this line;

testObject test=(((Object) map.get (key)));

should be;

testObject test=(((testObject) map.get (key)));

Cheers
Dominique


I noticed my mistake and edited my post above.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!