The similarities and differences between integers and ints in Java

Source: Internet
Author: User

1  Public voidTest1 () {2         intA = 128;3Integer B = 128;4Integer C = 128;5         //the integer is automatically disassembled into int, so the ture6System.out.println (a==b);7System.out.println (a==c);8     }9     Ten @Test One      Public voidTest2 () { AInteger A = 127; -Integer B = 127; -System.out.println (A = = B);//The result here is true, there should be no doubt Java compiles to integer.valueof (127) When compiling the Integer C the          -Integer C = 128; -Integer d = 128; -System.out.println (c = = d);//The result here is False, +         /*The integer.valueof () method caches numbers between [-128,127] based on reducing the number of objects created and memory-saving considerations.  - this number range incoming directly returns the object in the cache. Outside of this, direct new comes out. *///The source code is as follows +         /*Public static Integer valueOf (int i) { A assert Integercache.high >= 127; at if (i >= integercache.low && i <= integercache.high) - return integercache.cache[i + (-integercache.low)]; - return new Integer (i); -             }*/ -}

The similarities and differences between integers and ints in Java

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.