码迷,mamicode.com
首页 > 编程语言 > 详细

what is the difference between Integer and int in java?

时间:2019-02-10 00:25:56      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:represent   rom   rap   sed   ==   hat   value   static   ati   

int is a primitive type, Variables of int type store the actual binary value for the Integer type you want to represent.

Integer is a class, no diffeeent from any other in the java language. Variables of type Integer store the references to Integer Objects.

Note that every primiry type has wrapper class:

  byte has Byte

  long has Long

  boolean has Boolean

  float has Float

  double has Double

Wrapper class inherit from Object class, and primitive don‘t. So you can be used in collections with Object reference.

 

1. Integer与Integer的比较

public static void compare() {
        Integer i = new Integer(100);
        Integer i2 = new Integer(100);
        System.out.println( i == i2);    //false
}

2. int与Integer的比较

public static void compareIntWithInteger() {
        Integer i = new Integer(100);
        int i2 = 100;
        System.out.println( i == i2);    //true
}

 

what is the difference between Integer and int in java?

标签:represent   rom   rap   sed   ==   hat   value   static   ati   

原文地址:https://www.cnblogs.com/chenqr/p/10358161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!