What are the specific differences between Integer. valueof (String s) and Integer. parseInt (String s ?, Parseint and valueof

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.