当前位置: 代码迷 >> 综合 >> 使用 MapInteger,Integer 所犯低级错误
  详细解决方案

使用 MapInteger,Integer 所犯低级错误

热度:68   发布时间:2024-01-20 23:02:25.0

昨天在测试的时候,发现如下代码报 : Exception in thread "main" java.lang.NullPointerException

 Map<Integer,Integer> intMap = new HashMap<Integer,Integer>();intMap.put(1, 2);intMap.put(3, 3);if(intMap.get(2)==2){ //提示异常在此处
//			......}

突然在想起,Map中的get方法,如果key不存在的话,返回值是null。


以上是昨天犯的低级错误...

  相关解决方案