Set继承了Collection接口
方法
size
返回set中包含的元素个数,如果包含的元素多于Integer.MAX_VALUE,则返回Integer.MAX_VALUE;
int size();
contains
如果set中包含指定的元素,返回true。这分为两种情况,指定元素为null,set中也包含null或者指定元素为o,set中存在e使得o.equals(e)
/*
* @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
*/
boolean contains(Object o);
add
向set中添加元素,如果set中已经存在该元素,那么这次调用后set不变并返回false
/**
* @throws UnsupportedOperationException if the <tt>add</tt> operation
* is not supported by this set
* @throws ClassCastException if the class of the specified element
* prevents it from being added to this set
* @throws NullPointerException if the specified element is null and this
* set does not permit null elements
* @throws IllegalArgumentException if some property of the specified element
* prevents it from being added to this set
*/
boolean add(E e);
remove
从set中移除特定元素(o= =null ?e==null:o.equals(e))
/**
* @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>)
* @throws UnsupportedOperationException if the <tt>remove</tt> operation
* is not supported by this set
*/
boolean remove(Object o);