ArrayList as key in HashMap

前端 未结 9 1848
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 10:00

    Unlike Array, List can be used as the key of a HashMap, but it is not a good idea, since we should always try to use an immutable object as the key.

    .toString() method getting the String represtenation is a good key choice in many cases, since String is an immuteable object and can prefectly stands for the array or list.

提交回复
热议问题