Java容器之Collection_Set_List

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_45778981/article/details/102760968

Java容器之Collection_Set_List

各接口的特点

(1)Collection接口存储一组不唯一,无序的对象
(2)List接口存储一组不唯一,有序(索引顺序)的对象
(3)Set接口存储一组唯一,无序的对象

Collection

int size();测长度
boolean isEmpty(); 判断是否为空
boolean contains(Object o); 如果对象存在与集合中则返回true
Interator iterator(); 返回集合中的迭代器(可以使用foreath)
Object[] toArray(); 将集合转成数组
boolean add(E e); 添加元素
boolean remove(Object o);根据对象去删除
boolean containsAll(Collection<?> c); 你的集合中是否包含括号中集合的所给元素
boolean addAll(Collection<? extends E> c);把括号集合全部添加到你的集合中
boolean removeAll(Collection<?> c)删括号中所有在你的集合的元素
boolean retainAll(Collection<?> c);删除两个集合中的非相同元素
void clear(); 清空集合中所有元素
boolean equals(Object o);比较两个集合对象是否相同

Set

几乎全部继承Collecton

List

继承Collection
boolean addAll(int index,Collection<? extends E> c); 在指定位置添加
E get(int index) 根据索引位置返回元素
void add(int index, E element); 根据索引位置添加元素
E remove(int index) 根据索引删除

猜你喜欢

转载自blog.csdn.net/weixin_45778981/article/details/102760968
今日推荐