java.util.Set 接口直接继承自 java.util.Collection 接口。

一、Set接口特点或规范
不包含重复元素。至多一个 null 元素。数学意义的集合。
 
全部方法都继承自 java.util.Collection 接口。
 
子类实现必须创建一个不包含重复元素的构造函数。
 
子类实现必须对 equals() 和 hashCode() 方法重写,对 Set 进行 “值比较”。
 
某些子类实现对其包含的元素有限制。如:
 
某些实现禁止 null 元素
 
某些实现对其元素的类型有限制
 
二、继承自 Collection 的方法
详细方法描述,见:java.util.Collection 接口。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
   | 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); boolean addAll(Collection<? extends E> c); boolean retainAll(Collection<?> c); boolean removeAll(Collection<?> c); void clear();
 
  boolean equals(Object o); int hashCode();
  @Override default Spliterator<E> spliterator() {          return Spliterators.spliterator(this, Spliterator.DISTINCT); }
 
  |