Storing and Retrieving ArrayList values from hashmap

后端 未结 7 2505
感动是毒
感动是毒 2020-12-13 13:27

I have a hashmap of the following type

HashMap> map=new HashMap>();    
<         


        
相关标签:
7条回答
  • 2020-12-13 13:57

    You could try using MultiMap instead of HashMap

    Initialising it will require fewer lines of codes. Adding and retrieving the values will also make it shorter.

    Map<String, List<Integer>> map = new HashMap<String, List<Integer>>();
    

    would become:

    Multimap<String, Integer> multiMap = ArrayListMultimap.create();
    

    You can check this link: http://java.dzone.com/articles/hashmap-%E2%80%93-single-key-and

    0 讨论(0)
提交回复
热议问题