从map中匹配到一个key值,取到他对应的value
使用:public static void main(String[] args) { Map问题:integerMap = new HashMap<>(); Integer bb = 1000; Long cc = 1000L; integerMap.put(bb,111); System.out.println(integerMap.containsKey(cc)); //false }
当map使用containsKey时,会使用equals比较两个值是否相等
这里我们是Long和Integer比较。equals比较不通过
使用map的containsKey方法的时候,要注意类型问题。不然会有点坑
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)