【JAVA SE基础篇】41.Collection方法
1.Collection中的方法 Collection表示一组对象,他是集中、收集的意思。Collection接口有两个子接口List和Set接口 Cooleantion中的方法: 1.boolean add(Object element):增加元素到容器 2.boolean remove(Object element):从容其中删除元素 3.boolean contains(Object element):容器中是否包含该元素 4.int size():容器中元素的数量 5.boolean isEmpty():容器是否为空 6.void clear():清空容器中所有元素 7.Iterator iterator():获得迭代器,用于遍历所有元素 8.boolean containsAll(Collection c):本容器是否包含C容器中的所有元素 9.boolean addAll(Collection c):将容器C中所有元素增加到本容器 10.boolean remove(Collection c):移除本容器和容器C中都包含的元素 11.boolean retainAll(Collection c):取本容器和容器C中都包含的元素,移除非交集元素 12.Object[] toArray() :转化成Object数组 例(基本方法): 例(数学集合相关的方法): 来源: