> 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).