集合
1.概述:
Collection层次结构中的根接口。Collection 表示一组对象,这些对象也称为 collection 的元素。
一些 collection 允许有重复的元素,而另一些则不允许。
一些 collection 是有序的,而另一些则是无序的。
2. 特点:
a. 可以自动地调整自己的大小
b. 只能存储引用数据类型
3. API:
增:
boolean add(E e)
boolean addAll(Collection c)
删:
void clear()
boolean remove(Object o)
boolean removeAll(Collection c)
boolean retainAll(Collection c)
查:
boolean contains(Object o)
boolean containsAll(Collection c)
获取集合的属性:
boolean isEmpty()
int size()
遍历:
Object[] toArray()
4.自动拆箱 自动装箱
自动装箱和自动拆箱(JDK5)
- 自动装箱:基本数据类型转换成对应的引用数据类型 基本数据类型—> 引用数据类型
- 自动拆箱:引用数据类型转换成对应的基本数据类型 引用数据类型—> 基本数据类型
* 基本数据类型 引用数据类型
* byte Byte
* short Short
* int Integer
* long Long
* float Float
* double Double
* char Character
* boolean Boolean
public class CollectionDemo2 {
public static void main(String[] args) {
int intvalue = 10 ;
Integer integer = intvalue ;//装
int i = integer ; //拆
}
}