arraylist - when i use HashMap in java all my values get overrided. -



arraylist - when i use HashMap in java all my values get overrided. -

if hashmap

hashmap<string,arraylist<objects>> a;

if first key "dog" , value arraylist called object1. if add together key called "cat" , value arraylist called object2. object 2 arraylist overrides key dog value object 2. how prepare this? doing:

keywordsindex.put("dog", object1); keywordsindex.put("cat", object2);

i getting basically:

[dog=object2, cat=object2]

when want this:

[dog=object1, cat=object2]

please share code, can guess otherwise.

as per guess, dog , cat pointing same object or equal (same hashcode , equals), when you're setting cat=object2 it's overriding first key.

just test utilize below order:- keywordsindex.put("cat", object2); keywordsindex.put("dog", object1);

and check value or check map size after adding sec element.

java arraylist put

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -