HashMap and int as key

前端 未结 11 2058
说谎
说谎 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:04

    For everybody who codes Java for Android devices and ends up here: use SparseArray for better performance;

    private final SparseArray myMap = new SparseArray();
    

    with this you can use int instead of Integer like;

    int newPos = 3;
    
    myMap.put(newPos, newObject);
    myMap.get(newPos);
    

提交回复
热议问题