Test of the Java-integer class

Source: Internet
Author: User

Package com.day9.Wrapclass;

public class Demo {

public static void Main (string[] args) {
Integer i1 = new Integer (97);
Integer i2 = new Integer (97);
System.out.println (I1 = = i2);//false two objects, different address values
System.out.println (I1.equals (I2));//true
System.out.println ("-----------");

Integer i3 = new Integer (197);
Integer i4 = new Integer (197);
System.out.println (i3 = = i4);//false two objects, different address values
System.out.println (I3.equals (I4));//true
System.out.println ("-----------");

Integer i5 = 97;
Integer I6 = 97;
SYSTEM.OUT.PRINTLN (i5 = = I6);//true because the value range of byte is -128~127, if within this value range, automatic boxing will not
The newly created object is taken directly from the constant pool, and if a range of values is exceeded, the object is newly created
System.out.println (I5.equals (I6));//true
System.out.println ("-----------");

Integer i7 = 197;
Integer i8 = 197;
System.out.println (i7 = = i8);//false
System.out.println (I7.equals (i8));//true

}

}

Test of the Java-integer class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.