Talking about Java Packaging Class

Wrapper classes are a set of special classes in Java that are used to encapsulate basic data types (such as int, boolean, double, etc.) into objects. These classes provide many useful methods that can help us be more flexible and convenient when dealing with basic data types.

For example, if we need to process an integer and store it in a collection class, we need to use the Integer wrapper class to encapsulate the integer:

int num = 42;              // 基本数据类型
Integer wrappedNum = num;  // 将其封装成对象
List<Integer> list = new ArrayList<>();  // 创建一个集合类
list.add(wrappedNum);      // 将包装后的整数存储到集合中

In this way, we can handle basic data types through wrapper classes, and can easily manipulate these data

Guess you like

Origin blog.csdn.net/C_Small_Cai/article/details/130623686