[随笔] 工作中 一些java代码优化的记录
记录一下吧,有点时候整理起来有点麻烦
1.hashmap 的 containsKey和get方法 都会调用hash() 因此 要避免同时使用,可以用下面的工具类
public static <K> int getMapIntValue(Map<K, Integer> map, K k) {
return getMapIntValue(map, k, -1);
}
public static <K> int getMapIntValue(Map<K, Integer> map, K k, int defaultValue) {
Integer value = map.get(k);
if (value == null) {
return defaultValue;
} else {
return value;
}
}
持续更新吧 ......

浙公网安备 33010602011771号