Look at what you are using for keys. You said
i found that if i insert two different objects with same hashcode in the map they latter overrides the previous value
But you aren't using two different objects for keys. You're only using one object all the time, namely the Integer whose value is 1. Try actually using the Animals and Vegetables objects as keys, which I believe is what you meant to try.