Statement: This article is a reprinted article by the blogger. The original address can be found at the end of the article.
/*
* int is the 8 primitive types provided by java One of the data types. Java provides wrapper classes for each primitive type. Integer is the wrapper class provided by java for int. The default value of int is 0,
* and the default value of Integer is null
*, that is, Integer can distinguish the difference between unassigned value and value 0, int It is impossible to express the unassigned situation. For example, if you want to express the difference between not taking the exam and the exam score being 0
*, you can only use Integer
*. In JSP development, the default value of Integer is null, so when the el expression is used to display it in the text box, the value is a blank string, and the default value of int is 0, so when the el expression is used to display it in the text box
* , the result is 0, so int is not suitable as the form data type of the web layer.
* In Hibernate, if the OID is defined as an Integer type, then Hibernate can determine whether an object is temporary based on whether its value is null
* , if the OID is defined as int type, you also need to set its unsaved-value attribute to 0 in the hbm mapping file.
* In addition, Integer provides multiple integer-related operation methods, such as converting a string into an integer. Integer also defines constants that represent the maximum and minimum values of integers.
*/
##123 | System.out.println(Integer.valueOf(
"127" )==Integer.valueOf( "127" ));
System.out.println(Integer.valueOf(
"128" )==Integer.valueOf( "128" ));
System.out.println(Integer.parseInt(
"128" )==Integer.valueOf( "128" ));
|
##1 | ##new Integer(123);
|
##1 | ##Integer.parseInt( "123" );
|
#Integer.valueOf( | "123" );
| ##This situation is better than others It's a little more complicated. String parsing is done first, and then if the parsed value is between
Integer()
method will be called and the parsed value will be passed in as a parameter to get a new object. Now, let’s look at the 3 expressions in the question.
"127"
| )==Integer.valueOf(
"127" true);
| , because the value of
##1
)==Integer.valueOf( | "128"
);
The above expression returns only when both sides of the equation
value int |
The above is the detailed content of The difference between integer and int and the detailed explanation of integer.values() method. For more information, please follow other related articles on the PHP Chinese website!