Map key为Integer类型时用Long值取value问题

Map map1 = new ConcurrentHashMap();
			map1.put(11, "11");
			map1.put(22, "22");
			long key1 = 11;
			System.out.println(map1.get(key1));  // null
			
			Map map2 = new ConcurrentHashMap();
			map2.put(11L, "11");
			map2.put(22L, "22");
			int key2 = 11;
			System.out.println(map1.get(key2));  // 11


总结: Map的key为Integer时,用Long型值无法取到value;Map的key为Long时,用Integer值可以取到value。



你可能感兴趣的:(JAVA)