How to have a key with multiple values in a map?

前端 未结 6 626
轻奢々
轻奢々 2020-12-10 17:10

I have a map like this

Map map=new HashMap();//HashMap key random order.
map.put(\"a\",10);
map.put(\"a\",20);
map.put(\"a\",30);
map.put(\"b\",10);

System.         


        
6条回答
  •  不知归路
    2020-12-10 17:52

    Use Map with value type as list of values..For example, in your map, while adding an entry, you will put key as "a" and you will have to add it's value as a list of Integer , having all the required values, like 1,2,3,4.

提交回复
热议问题