This article mainly introduces the comparison of two methods of converting Java Integer to int. It has a very good reference value. Let’s take a look at it with the editor.
Method 1:
Integer.parseInt(); Returns an int value.
Method 2:
new Integer.valueof(); 返回的是 Integer 的对象。 new Integer.valueof().intValue(); 返回的也是一个 int 的值。
Written test application examples:
Set the following two assignment statements:
a = Integer.parseInt(“123”); b = Integer.valueOf(“123”).intValue();
The following statement is correct (d)
A. a is an integer type variable, and b is an integer type object.
B, a is an integer type object, and b is an integer type variable.
C, a and b are all integer class objects and their values are equal.
D, a and b are all integer type variables and their values are equal.
For more related articles comparing the two methods of converting Integer to int in Java, please pay attention to the PHP Chinese website!