首页 > 编程语言 > 详细

[随笔] 工作中 一些java代码优化的记录

时间:2017-11-01 18:36:16      阅读:259      评论:0      收藏:0      [点我收藏+]

记录一下吧,有点时候整理起来有点麻烦

 

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;
    	}
    }

  

 

 

持续更新吧 ...... 

[随笔] 工作中 一些java代码优化的记录

原文:http://www.cnblogs.com/TinyBobo/p/7767833.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!