Java Wrapper class Introduction (i) (wrapper class, basic type Data)

Source: Internet
Author: User

1. Packaging classes convert basic type data to Objects

1.1 Each base type has a corresponding wrapper class in the Java.lang package

2. What is the role of the packaging class?

2.1 provides a series of practical methods

2.2 Collection is not allowed to hold basic data type data, when storing numbers, use the wrapper type

3. How to construct the packing class

3.1 All wrapper classes can use their corresponding base data types as parameters to construct their instances

Public type (type value)

such as: Integer I=new integer (1);

3.2 In addition to the character class, other wrapper classes can construct their instances with a string as a parameter

Public Type (String value)

such as: Integer i=new integer ("123");

3.3 Precautions:

(1) If the Boolean constructor method parameter is a string type, the string content is

True (regardless of case), the Boolean object represents true, otherwise false is represented.

(2) When the number wrapper class constructs a method parameter of type string, the string cannot be null.

And the string must be resolvable to the data of the corresponding base data type, otherwise compiled through, run-time numberformatexception exception.

Java Wrapper class Introduction (i) (wrapper class, basic type Data)

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.