Iterable、Collection、List 的常见方法签名以及含义

目录

1.Iterable、Collection、List三者间的关系

2.Collection常用方法

3.List常用方法


1.Iterable、Collection、List三者间的关系

Iterable、Collection、List 的常见方法签名以及含义_第1张图片

2.Collection常用方法

            public int size() ;//返回集合中的元素
 
            public boolean isEmpty();//判断集合是否为空

            public boolean contains(Object o);//判断集合中是否含有指定元素

            public Iterator iterator();//迭代器

            public Object[] toArray();//将集合转换为数组

            public boolean add(Integer integer);//添加元素

            public boolean remove(Object o);//删除元素

            public boolean addAll(Collection c);//添加集合

            public boolean removeAll(Collection c);//删除集合

            public void clear();//清空数组

3.List常用方法

List是一个接口,继承Collection。

方法 解释
boolean add(E e) 尾插e
void add(int index,E e) 将e插入到index的位置
boolean addAll(Collectionc) 尾插c中的元素
E remove(int index) 删除index位置的元素
boolean remove(Object o) 删除第一次出现的o
E get(int index) 获取下标index位置的元素
E set(int index,E e) 将index位置的元素设置为e
void clear() 清空

注:List是一个接口,不能直接用来实例化!!!

你可能感兴趣的:(java,数据结构)