Get the App
SLTechnology News&Howtos  ›  Development  › 

Problems encountered by Java in modifying the value of Integer variables and their Solutions

Shulou Source: shulou.com Published: 2022-06-03 11:42:07 10月30日 Update

This article mainly introduces the "problems and solutions encountered when Java modifies the value of Integer variables". In daily operation, I believe many people have doubts about the problems and solutions encountered by Java in modifying the value of Integer variables. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the problems and solutions encountered in modifying the value of Integer variables by Java. Next, please follow the editor to study!

Catalogue

Java modifies the value of Integer variable

Now I have tried two ways to change the integer value of Integer

Look at the source code

Problems that need to be paid attention to in Integer value

Reason

Solution.

Java modifies the value of Integer variable

For Integer variables, it is common to compare variable values as follows:

Integer a = 1000; Integer b = 1000; Integer c = 100; Integer d = 100; System.out.println (a = = b); System.out.println (c = = d)

"=" compares the value of the address, so the correct answer is false,true

When we directly assign a value to an Interger variable with the "=" sign, it is equivalent to automatic boxing, that is, converting the int variable on the right (the default is int for integers) into an Integer variable, and let's take a look at the source code

/ * Returns an {@ code Integer} instance representing the specified * {@ code int} value. If a new {@ code Integer} instance is not * required, this method should generally be used in preference to * the constructor {@ link # Integer (int)}, as this method is likely * to yield significantly better space and time performance by * caching frequently requested values. * * This method will always cache values in the range-128to 127, * inclusive, and may cache other values outside of this range. * * @ param i an {@ code int} value. * @ return an {@ code Integer} instance representing {@ code I}. * @ since 1.5 * / public static Integer valueOf (int I) {assert IntegerCache.high > = 127; if (I > = IntegerCache.low & & I

Tags: Variables methods problems copies addresses source code types learning between results values packing consistency success that is memory method interval reason Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Xiaomi Shulou Tech Info MariaDB vpn