java.lang包中的Integer类是我们比较常用的类,比如以下代码:

Integer a=new Integer(1)

Integer a=Integer.valueOf(1);

两个都是得到一个Integer对象,但是Integer.valueOf的效率高。为什么呢?因为Integer.valueOf用到了缓存机制。

new Integer(1)和Integer.valueOf(1)的区别的更多相关文章

  1. Integer.parseInt()和Integer.valueOf()有什么区别

    jdk的源代码的时候注意到Integer.parseInt(s) 和 Integer.valueOf(s)的具体代码的实现有所区别: Java代码 public static int parseInt ...

  2. 区分Integer.getInteger和Integer.valueOf、Integer.parseInt() 的使用方法

    Integer类有两个看起来很类似的静态方法,一个是Integer.getInteger(String),另外一个是Integer.valueOf(String).如果只看方法名称的话,很容易将这两个 ...

  3. Integer缓冲区相关问题--valueOf()方法

    今天在学习过程中了解到一个现象,代码如下: Integer num1 = 100; Integer num2 = 100; System.out.println(num1==num2?true:fal ...

  4. Integer、new Integer() 和 int 比较的面试题

    基本概念的区分: 1.Integer 是 int 的包装类,int 则是 java 的一种基本数据类型2.Integer 变量必须实例化后才能使用,而int变量不需要3.Integer 实际是对象的引 ...

  5. Integer和new Integer

    Java code   ? 1 2 3 4 5 6 7 8 9 10 public static void main(String[] args) {     Integer i1=10;     I ...

  6. 一篇文章搞明白Integer、new Integer() 和 int 的概念与区别

    基本概念的区分 1.Integer 是 int 的包装类,int 则是 java 的一种基本数据类型 2.Integer 变量必须实例化后才能使用,而int变量不需要 3.Integer 实际是对象的 ...

  7. 傻傻分不清?Integer、new Integer() 和 int 的面试题

    这篇有意思: 基本概念的区分: 1.Integer 是 int 的包装类,int 则是 java 的一种基本数据类型 2.Integer 变量必须实例化后才能使用,而int变量不需要 3.Intege ...

  8. Integer 类和 int 基本数据类型的区别

    public static void main(String[] args) { Integer i = 10; Integer j = 10; System.out.println(i == j); ...

  9. 关于Integer类中parseInt()和valueOf()方法的区别以及int和String类性的转换.以及String类valueOf()方法

    Integer类中的. 关于parseInt()方法的API文档.  返回的是int类型的 关于valueOf()方法的API文档 返回的是Integer类型的. 关于intValue()方法的API ...

随机推荐

  1. bzoj 3505: [Cqoi2014]数三角形 组合数学

    3505: [Cqoi2014]数三角形 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 478  Solved: 293[Submit][Status ...

  2. Book of Evil

    Codeforces Round #196 (Div. 2) D:http://codeforces.com/contest/337/status/D 题意:给你一个树,然后树中有一m个点,求到这m个 ...

  3. MySQL的if,case语句

    IF表达式 IF(expr1,expr2,expr3) 如果 expr1 是TRUE (expr1 <> 0 and expr1 <> NULL),则 IF()的返回值为exp ...

  4. android通用文件操作

    最经用到android的SCCard的文件操作,因此稍作了整理,将它写成一个简单的工具类.其中,可以判断SDCard的是否可用,可用存储空间,文件的创建以及写入数据.经过测试,可以正常使用.代码如下: ...

  5. 5个最佳免费Linux杀毒软件

    5个最佳免费Linux杀毒软件 Linux的防病毒软件,开玩笑吧?Linux不是很安全吗?很多Linux新手都这样认为,看到标题不要犹豫,读完全文你就会从中找到答案. 首先,Linux比其它操作系统更 ...

  6. bzoj1912

    由于k只有2,所以我们分类讨论显然当k=1时,我们只要连一条最长的路径即可就是树的直径L少走了L-1条边如果k=2时,我们再次连边成环后如果成环路径与上一次的最长路径没有相同的边,那少走的边数是路径长 ...

  7. luoguP2267 琪琪的项链

    题目:http://www.luogu.org/problem/show?pid=2267 题解:这题略吊. 看了之后发现不能用组合数学直接得出公式,然后如果直接暴力也不知道如何去排除两个颜色序列相同 ...

  8. 网络流(最大流)CodeForces 512C:Fox And Dinner

    Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). T ...

  9. 数据结构(主席树):HZOI 2016 采花

    [题目描述] 给定一个长度为n,包含c种颜色的序列,有m个询问,每次给出两个数l,r,表示询问区间[l,r]中有多少种颜色的出现次数不少于2次. 本题强制在线,对输入的l,r进行了加密,解密方法为: ...

  10. jQuery、实例大全

    文章出处 http://www.cnblogs.com/suoning/p/5683047.html 一.简介 定义 jQuery创始人是美国John Resig,是优秀的Javascript框架: ...