Java集合之list接口与set接口

本文详细介绍了Java集合框架中的List和Set接口,包括它们的主要方法及其功能。List接口提供了有序元素集合的操作,如添加、删除和查找等;而Set接口则确保了元素的唯一性,不允许重复元素的存在。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public interface List<E> extends Collection<E> {//有序队列       jdk:1.7  java.util
    int size();//返回列表中的元素数
    boolean isEmpty();//是否包含元素
    boolean contains(Object o);//是否包含指定的元素
    Iterator<E> iterator();//获取迭代器
    Object[] toArray();//返回数组
    <T> T[] toArray(T[] a);//返回数组,保留类型
    boolean add(E e);//向列表的尾部添加指定的元素
    boolean remove(Object o);//从此列表中移除第一次出现的指定元素
    boolean containsAll(Collection<?> c);//列表石是否包含指定 c中所有元素
    boolean addAll(Collection<? extends E> c);//添加指定 collection 中的所有元素到此列表的结尾
    boolean addAll(int index, Collection<? extends E> c);//将指定 collection 中的所有元素都插入到列表中的指定位置
    boolean removeAll(Collection<?> c);//从列表中移除指定 collection 中包含的其所有元素
    boolean retainAll(Collection<?> c);//仅在列表中保留指定 collection 中所包含的元素
    void clear();//清空
    boolean equals(Object o);//比较指定的对象与列表是否相等
    int hashCode();//返回列表的哈希码值
    E get(int index);//返回列表中指定位置的元素
    E set(int index, E element);//用指定元素替换列表中指定位置的元素
    void add(int index, E element);//在列表的指定位置插入指定元素
    E remove(int index);//移除列表中指定位置的元素
    int indexOf(Object o);//返回此列表中第一次出现的指定元素的索引
    int lastIndexOf(Object o);//返回此列表中最后出现的指定元素的索引
    ListIterator<E> listIterator();//返回此列表元素的列表迭代器(按适当顺序)
    ListIterator<E> listIterator(int index);//返回列表中元素的列表迭代器(按适当顺序),从列表的指定位置开始
    List<E> subList(int fromIndex, int toIndex);
}

public interface Set<E> extends Collection<E> {//不允许有重复元素      jdk1.7   java.util
    int size();//set 中的元素数
    boolean isEmpty();//如果set不包含元素,则返回 true。
    boolean contains(Object o);//是否包含指定的元素
    Iterator<E> iterator();//获取迭代器
    Object[] toArray();//返回数组
    <T> T[] toArray(T[] a);//返回数组,保留类型
    boolean add(E e);//如果 set中尚未存在指定的元素,则添加此元素
    boolean remove(Object o);//如果 set中存在指定的元素,则将其移除
    boolean containsAll(Collection<?> c);//如果此 set 包含指定 collection的所有元素,则返回 true
    boolean addAll(Collection<? extends E> c);//如果 set 中没有指定 collection中的所有元素,则将其添加到此 set中
    boolean retainAll(Collection<?> c);//仅保留 set中那些包含在指定 collection 中的元素
    boolean removeAll(Collection<?> c);//移除 set中那些包含在指定 collection 中的元素
    void clear();//清空
    boolean equals(Object o);//比较指定对象与此 set 的相等性
    int hashCode();//返回 set 的哈希码值
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值