java集合:Collection,List,Vector,Enumeration,LinkedList接口的常用方法

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)

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

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集合特有的迭代器)

Vector

public void addElement(E obj) 

添加指定元素

public E elementAt(int index) 

返回索引处的元素

public boolean removeElement(Object obj) 

移除指定元素,从此集合中移除变量的第一个(索引最小的)匹配项。如果有则返回true

public void removeElementAt(int index) 

删除指定索引处的元素

public void setElementAt(E obj, int index)

将指定索引处的元素替换为指定对象

public Enumeration<E> elements()

以枚举的形式返回此集合的内容

Enumeration

public boolean hasMoreElements()

如果还有更多元素则返回true

public Object nextElement()

返回下一个枚举元素

LinkedList

public void addFirst(E e) 

将指定元素添加到此列表开头

public void addLast(E e) 

将指定元素添加到此列表的末尾

public E getFirst()

返回此列表的第一个元素

public E getLast()

返回此列表的最后一个元素

public E removeFirst()

移除此列表的第一个元素

public E removeLast()

移除此列表的最后一个元素

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值