Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report