集合-Collection和List接口

Collection:

public boolean add(E e)

将指定元素添加到集合中

public boolean addAll(Collection c)

将指定集合的所有元素添加到此集合中

public void clear()

移除此集合中的所有元素

public boolean remove(Object o)

移除移除元素中的指定对象,如果存在返回true并移除,没有则返回false

public boolean removeAll(Collection c)

移除此集合中也包含在指定集合中的元素,有移除操作返回true,没有则返回false

public boolean contains(Object o)

扫描二维码关注公众号,回复: 2826397 查看本文章

判断此集合中是否包含指定元素

public boolean containsAll(Collection c)

如果此 collection 包含指定 collection 中的所有元素,则返回 true

public boolean isEmpty()

判断此集合是否为空,不包含元素则为true

public Iterator<E> iterator()

返回一个迭代器实例

public boolean retainAll(Collection<?> c)

取交集,仅保留此 collection 中那些也包含在指定 collection 的元素并将交集元素赋给此集合,如果交集为空,则将此集合置为空。如果此集合变化则返回true

public int size()

返回此集合的元素数

public Object[] toArray()

此集合转为object数组

List:

public void add(int index, Object element)

此集合的指定索引处添加指定元素

public boolean remove(int index)

移除此列表中指定索引处的元素

public Object set(int index, Object element)

指定元素替换指定索引出的元素

public Object get(int index)

返回列表中指定位置的元素

public ListIterator listIterator()

返回列表迭代器(List集合特有的迭代器)

 

猜你喜欢

转载自blog.csdn.net/qq_38454165/article/details/81359890