ArrayList as key in HashMap

前端 未结 9 1857
Happy的楠姐
Happy的楠姐 2020-11-29 09:17

Would it be possible to add an ArrayList as the key of HashMap. I would like to keep the frequency count of bigrams. The bigram is the key and the

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 09:58

    Try this ,this will work.

     public Map getBigramMap (String word1,String word2){
        Map hm = new HashMap();
        List arrList1 = new ArrayList();
        arrList1 = getBigram(word1, word2);     
        if(hm.get(arrList1) !=null){
            hm.put(arrList1, hm.get(arrList1)+1);
        }
        else {
            hm.put(arrList1, 1);
        }
    
        System.out.println(hm.get(arrList1));
        return hm;
    }
    

提交回复
热议问题