Java Fundamentals--equality

Source: Internet
Author: User

Learning: http://www.cnblogs.com/dolphin0520/p/3780005.html#3163302

After discovering that there is such a thing, of course, will not pay attention to what the automatic unpacking and boxing, only know the use of the line. But it's worth noting here that the automatic valueof implementation of an integer is scoped:

When you create an integer object by using the ValueOf method, if the value is between [-128,127], a reference to the object that already exists in Integercache.cache is returned, otherwise a new integer object is created.

Nothing else would have happened. So take a look at a few tests:

  Public Static voidMain (string[] args) {Integer i1= 100; Integer I2= 100; Integer i3= 200; Integer I4= 200; System.out.println ("=======integer============"); System.out.println (I1==i2); SYSTEM.OUT.PRINTLN (i3==I4); System.out.println ("=======double============"); Double D1= 12.0; Double D2= 12.0; Double m=123456.12; Double N= 123456.12; DoubleD3 = 12.0; System.out.println (M==N); System.out.println (D1==D2); System.out.println (D1==D3); System.out.println ("=======string============"); String a= "123"; String b= "123"; System.out.println (A==b);    System.out.println (A.equals (b)); }
=======integer============truefalse=======double============ false True=======string============truetrue

Java Fundamentals--equality

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.