Collection接口的方法&List接口的常用方法(collection的子类)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_44213634/article/details/99062173
Collection接口的方法
boolean add(E e) ;/ int size(); 向集合中添加元素e/返回集合中元素的个数
boolean addAll(collection<? extends E> c) 将集合c中的所有元素添加到当前这个集合中
boolean contains(object O) 如果该集合中包含对象O,返回true
boolean isEmpty(); 如果集合不包含任何元素返回true
Iterator <E> iterator(); 返回集合中元素所使用的迭代器
boolean remove(Object o); 从集合中删除元素o
boolean removeAll(collection< ?> c); 从集合中删除所有的元素
boolean retainAll(collection<?> c); 保留c和该集合共有的元素(交集)
Object toArray();

返回该集合构成的object数组

void clear(); 删除集合中所有的元素
List接口的常用方法(collection的子类)
public void add(int index,E element);/add (Object o); 在指定位置添加元素/向集合中添加元素
public boolean addAll(int index,collection<? extends c>);/addAll(collection<? extends c>); 在指定位置添加一组元素/添加一组元素
E get(int index); 返回指定位置的元素
public int indexOf(Object o); 查找指定元素的位置
public int lastIndexOf(Object o); 从后往前查找指定元素的位置
public ListIterator<E> listIterator() 获得List迭代器对象
public E remove(int index); 删除指定位置的元素
public List<E> subList(int fromIndex ,int toIndex); 取出集合中的子集合
public E set (int index, E element); 替换指定位置的元素
E set (int index,E element); 替换指定位置的元素

猜你喜欢

转载自blog.csdn.net/qq_44213634/article/details/99062173