Java ArrayList collection store basic data foundation

/*


 * If you want to send the basic type data of cinch in the collection ArrayList, you must use the "wrapping class" corresponding to the
 basic type * Basic type packaging class (reference type, the packaging is located under the Java.lang package)
 * byte Byte
 * short Short
 * int Integer [ Special]
 * long Long
 * float Float
 * double Double
 * char Character [special]
 * boolean Boolean
 * 
 * Starting from JDK 1.5+, support automatic boxing, automatic unboxing
 * 
 * Automatic boxing: basic type-> packaging type
 * Automatic unpacking: packaging type-> basic type
 * /

public class Test06ArrayListBasic {

	public static void main(String[] args) {
		ArrayList<String> listA=new ArrayList<>(); 
	//错误写法!泛型只能是引用类型,不能是基本类型
		//ArrayList<int> list=new ArrayList<>();
		
		ArrayList<Integer> listB=new ArrayList<>();
		listB.add(10);
		listB.add(1000);
		System.out.println(listB);//result:[10, 1000]
		
		//获取集合元素
		int num=listB.get(1);
		System.out.println("获取的1号元素 ="+num);//1000
		
	}

}

                                                                                                                                                                     20-4-20

                                                                                                                                                                      Learning record

Published 10 original articles · Likes0 · Visits 86

Guess you like

Origin blog.csdn.net/Q791425037/article/details/105644707