java集合类分析-set

时间:2023-02-15 10:01:36
// 集合是不同于线性表的一种数据的组织结构它要求集合的内部不能有相同的元素。对于//的jdk中对于set接口的解释有的set的实现类是允许有空值,有的不允许。 public interface Set<E> extends Collection<E> { //返回集合的最大值,当集合中数据的量超过int的最大值发挥int的最大值 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); //是否包含c中的所有元素 boolean containsAll(Collection<?> c); //把c 中的元素全部加入的该集合中 boolean addAll(Collection<? extends E> c); //删除除了c中其他的集合中元素 boolean retainAll(Collection<?> c); //删除集合中包括c中的元素 boolean removeAll(Collection<?> c); //清空集合 void clear(); boolean equals(Object o); int hashCode(); }