目录
批量操作 containsAll,addAll,removeAll,retainAll,clear
其余 equals,hashCode,spliterator
简介
/**
* <p>一个包含不重复元素的集合。
* 更正式地说,set不包含这样的元素对,e1和e2,e1.equals(e2),并且最大有一个null元素。
* 顾名思义,该接口对数学集抽象进行建模。
*
* <p>Set接口在从Collection接口继承来的方法,对所有的构造器,add,equals,hashCode方法,有着额外的约定。
* 为了方便起见,这里还包含了其他继承方法的声明。(伴随这些声明的规范是针对Set接口定制的,但是它们不包含任何额外的规定。)
*
* <p>关于构造器的额外规定是,所有的构造器必须创造一个不包含重复元素的set。
*
* <p>注意:如果使用可变对象作为set的元素,必须十分小心。
* 如果一个对象的值改变了,影响了equals的比较,同时是set的一个元素,set的行为没有被规定。
* 禁止的一个特殊情况是不允许set中,不允许把自己作为一个元素。
*
* <p>一些set的实现可能对可以包含的元素有限制。
* 例如一些实现禁止null元素,一些对元素的类型有限制。
* 尝试加入一个非法的元素会抛出未检查异常,通常是NullPointerException,ClassCastException。
* 尝试查询非法元素的存在可能抛出异常,或者紧急返回false。
* 一些实现会显示前一种行为,一些显示后面的行为。
* 更一般地说,尝试对不符合条件的元素执行操作,而该元素的完成不会导致将不符合条件的元素插入到set中,这可能会引发异常,
* 也可能会成功,取决于实现的选择。在这个接口的规范中,这些异常被标记为“可选”。
*
* @param <E> the type of elements maintained by this set
*
* @author Josh Bloch
* @author Neal Gafter
* @see Collection
* @see List
* @see SortedSet
* @see HashSet
* @see TreeSet
* @see AbstractSet
* @see Collections#singleton(java.lang.Object)
* @see Collections#EMPTY_SET
* @since 1.2
*/
public interface Set<E> extends Collection<E>
查询操作 size,isEmpty,contains
// Query Operations
/**
* 返回集合中元素的数量。如果set包含超过Integer.MAX_VALUE的元素,返回Integer.MAX_VALUE
*
* @return the number of elements in this set (its cardinality)
*/
int size();
/**
* 如果set不包含任何元素,返回true
*
* @return <tt>true</tt> if this set contains no elements
*/
boolean isEmpty();
/**
* 如果set包含指定元素,返回true。
* 更正式地,当且仅当集合至少有一个这样的元素时,返回true。
* <tt>(o==null ? e==null : o.equals(e))</tt>.
*
* @param o element whose presence in this set is to be tested
* @return <tt>true</tt> if this set contains the specified element
* @throws ClassCastException if the type of the specified element
* is incompatible with this set
* (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if the specified element is null and this
* set does not permit null elements
* (<a href="Collection.html#optional-restrictions">optional</a>)
*/
boolean contains(Obj