HashMap and int as key

前端 未结 11 2059
说谎
说谎 2020-11-28 23:32

I am trying to build a HashMap which will have integer as keys and objects as values.

My syntax is:

HashMap myMap = new HashMap&         


        
11条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 00:05

    Use Integer instead.

    HashMap myMap = new HashMap();
    

    Java will automatically autobox your int primitive values to Integer objects.

    Read more about autoboxing from Oracle Java documentations.

提交回复
热议问题