[随笔] 工作中 一些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;
    	}
    }

  

 

 

持续更新吧 ...... 

posted @ 2017-11-01 18:21  可爱的波儿胖  阅读(242)  评论(0编辑  收藏  举报

友情链接 : CodeForge源码分享