Help needed for basic map creation

Can we create a map with an object as value and its attribute as its key?map.put(object.attrib, object)I also got one more problemwhen using map.put(1, object1)map.put(2.object2) //this is overiding the first onecould you tell me what is happening
[289 byte] By [MSatyajita] at [2007-10-3 10:09:56]
# 1
I am sorry, the mistake was somewhere else.. .what i said is correct
MSatyajita at 2007-7-15 5:29:46 > top of Java-index,Core,Core APIs...
# 2

> Can we create a map with an object as value and its

> attribute as its key?

> map.put(object.attrib, object)

What happened when you tried? The answer is of course: yes you can. For example, it's pretty common to store objects in a map based on some sort of ID that can be retrieved from the object itself: map.put(object.getId(), object).

> I also got one more problem

>

> when using map.put(1, object1)

> map.put(2.object2) //this is overiding the first

> one

>

> could you tell me what is happening

Assuming the second line is map.put(2, object2), and by "overiding" you mean "overwriting" in the sense that your map only contains the second mapping: the only way it will overwrite the first mapping is when 1 is equal to 2 (which obviously isn't the case for ints).

Herko_ter_Horsta at 2007-7-15 5:29:46 > top of Java-index,Core,Core APIs...
# 3
Yes I can create a map with the syntax map(obj.attrib, obj)actually my code messed up due to one another assumption. Anyway thanks for your reply
MSatyajita at 2007-7-15 5:29:46 > top of Java-index,Core,Core APIs...