使用 Map<Integer,Integer> 所犯低级错误

来源:互联网 发布:linux 挂载硬盘方式 编辑:程序博客网 时间:2024/04/30 05:28

昨天在测试的时候,发现如下代码报 : 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。


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

0 0
原创粉丝点击