HashMap with multiple values under the same key

前端 未结 22 1883
旧时难觅i
旧时难觅i 2020-11-22 06:49

Is it possible for us to implement a HashMap with one key and two values. Just as HashMap?

Please do help me, also by telling (if there is no way) any other way to

22条回答
  •  醉酒成梦
    2020-11-22 07:06

    Apache Commons collection classes can implement multiple values under same key.

        MultiMap multiMapDemo = new MultiValueMap();
    
        multiMapDemo .put("fruit", "Mango");
        multiMapDemo .put("fruit", "Orange");
        multiMapDemo.put("fruit", "Blueberry");
    
        System.out.println(multiMap.get("fruit"));
    

    Maven Dependency

        
         
     
    热议问题