Home >Java >Javagetting Started >Boxing and unboxing in java

Boxing and unboxing in java

王林
王林forward
2019-11-28 16:20:361969browse

Boxing and unboxing in java

#1. What is boxing? What is unboxing?

Boxing: The process of converting a basic type into a wrapper type.

Unboxing: The process of converting a wrapper type into a basic type.

Online learning video sharing: java online tutorial

2. What is the execution process of boxing and unboxing

Boxing is achieved by calling the valueOf method of the wrapper class;

Unboxing is achieved by calling the xxxValue method of the wrapper class, xxx represents the corresponding basic data type.

For example: the valueOf(int) method of Integer is automatically called when int is boxed; Integer is automatically called when unboxing##intValue method of #Integer.

3. Frequently Asked Questions

(1) Integer packaging class

valueOf When the method returns an object, within the commonly used value range, The cache object will be returned.

(2) Floating-point wrapper class

valueOf method returns a new object.

(3) Boolean wrapper class

valueOf method BooleanStatic constant of class TRUE | FALSE.

More related articles and tutorials are recommended:

Getting started with java development

The above is the detailed content of Boxing and unboxing in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete