What are the specific differences between Integer. valueof (String s) and Integer. parseInt (String s ?, Parseint and valueof
What are the specific differences between Integer. valueof (String s) and Integer. parseInt (String s?
Integer. valueof (String s) is to convert a variable whose actual value is a number into a string type before converting it into an Integer type packaging Class Object (equivalent to an int object) in this way, the converted object has methods and attributes.
However, Integer. parseInt (String s) only converts a numeric String into a number. Note that the int type variable does not have methods and attributes.
There are two assignment statements:
A = Integer. parseInt ("123 ");
B = Integer. valueOf ("123"). intValue ();
Which of the following statements is true? (d ).
A and a are integer variables, and B are integer objects.
B. a is an integer object, and B is an integer variable.
C, a, and B are integer objects and their values are equal.
D, a, and B are both integer-type variables and their values are equal.
Explanation:
The parseInt (Strings) method is a static Integer-like method. It converts the form parameter s to an Integer, for example:
Interger. parseInt ("1") = 1;
Integer. parseInt ("20") = 20;
Integer. parseInt ("324") = 324;
Of course, the integer represented by s must be valid; otherwise, an exception is thrown.
ValueOf (Strings) is also a static method of the Integer class. Its function is to convert the form parameter s to an Integer object,
What is an Integer object? Integer is the int type packaging class of the basic data type. It is used to package int into a class, which is required in many cases. If you cannot understand it, you will think that int is an Integer mini version, which is much easier to use, but some functions are also lost. Well, check the Code:
Interger. valueOf ("123") = Integer (123)
At this time, Integer (123) is the object representation of Integer 123. It then calls the intValue () method to convert the Object Representation of 123 to the basic data 123.
Therefore, select D