Java wrapper class

Source: Internet
Author: User

In order for the basic data type to have the properties of the object, Java provides a wrapper class for each of the basic data types, so that we can manipulate the basic data type like an object, and the wrapper class is in the Java.lang package.

Correspondence between the base type and the wrapper class:

The wrapper class provides two main types of methods:

1. Ways to convert this type and other basic types

2. Ways to convert strings and this type and wrapper class to each other

such as: The General method of the integer wrapper class

It is often necessary to convert between the basic type and the wrapper class, and the conversion between the wrapper class and the base type is much easier after JDK1.5 introduces the mechanism of automatic boxing and unpacking.

Boxing: convert the basic type of the corresponding packaging class, so that it has the nature of the object, but also can be divided into manual boxing and automatic packing

unpacking: In contrast to boxing, the wrapper class object is converted to the corresponding basic type value, and can be divided into manual unpacking and automatic unpacking

Conversions between basic types and strings

There are three ways to convert a base type to a string:

1. Use the ToString () method of the wrapper class

2. Using the ValueOf () method of the String class

3. Using an empty string with the base type, you get the string that corresponds to the base type data

Again, there are two ways to convert a string to a basic type:

1. Call the Parsexxx static method of the wrapper class

2. The ValueOf () method that calls the wrapper class is converted to the basic type of wrapper class, and the box is automatically disassembled

Java wrapper class

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.