The integer buffer for Java

Source: Internet
Author: User

The java.lang.Integer.valueOf (int) method, by default, returns the object in the cache if the parameter is between 128 and 127, otherwise returns a new Integer (int).

The objects in the cache are initialized the first time the JVM uses the ValueOf method.

You can set system Properties Java.lang.Integer.IntegerCache.high the upper limit of the modified buffer, which defaults to 127. The parameter content should be a string in the form of a decimal number greater than 127, otherwise it will be ignored. The value range is 127-long.max_value, but is strongly converted to int.

When integer is used extensively in the system, increasing the upper limit of the cache can save a small amount of memory.

The upper buffer limit will affect some businesses:

Integer I1 =127; Integer I2=127; if(I1 = =I2) System. out. println (true); ElseSystem. out. println (false); I1= -; I2= -; if(I1 = =I2) System. out. println (true); ElseSystem. out. println (false);

The above code will output by default:

     true     false

When the modified buffer limit is greater than 128, it becomes:

  

true true  

The integer buffer for 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.