day07-常用类-ArrayList-基本类型的存储方式_转换为包装类
This commit is contained in:
31
day07/src/com/inmind/arraylist03/Demo09.java
Normal file
31
day07/src/com/inmind/arraylist03/Demo09.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.inmind.arraylist03;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/*
|
||||
ArrayList_基本类型的存储方式_转换为包装类
|
||||
|
||||
自动装箱:int 型的值 -----装箱成Integer类型的对象
|
||||
自动拆箱:Integer类型的对象-----拆箱为int型的值
|
||||
4类8种的基本数据类型不能存放到集合中,因为集合只能存放引用数据类型
|
||||
|
||||
在java中使用包装类,来对基本数据类型进行包装,包装成引用数据类型
|
||||
|
||||
引用数据类型:数组 类 接口
|
||||
基本数据类型:int char boolean byte short long float double 四类八种
|
||||
*/
|
||||
public class Demo09 {
|
||||
public static void main(String[] args) {
|
||||
//定义一个集合保存int类型的数据
|
||||
ArrayList<Integer> lists = new ArrayList<>();
|
||||
lists.add(1);//自动装箱: 1 ----> new Integer(1)
|
||||
lists.add(2);
|
||||
lists.add(3);
|
||||
System.out.println(lists);
|
||||
|
||||
//获取集合中第二个值(包头不包尾,从0开始)
|
||||
Integer i = lists.get(1);
|
||||
int value = i+10;//自动拆箱:integer i ----> int 2
|
||||
System.out.println(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user