remove
boolean remove(Object o)如果 set 中存在指定的元素,则将其移除(可选操作)。更确切地讲,如果此 set 中包含满足 (o==null ? e==null : o.equals(e)) 的元素 e,则移除它。如果此 set 包含指定的元素(或者此 set 由于调用而发生更改),则返回 true(一旦调用返回,则此 set 不再包含指定的元素)。 指定者:
接口 Collection<E> 中的 remove
参数:
o - 从 set 中移除的对象(如果存在)
返回:
如果此 set 包含指定的对象,则返回 true
抛出:
ClassCastException - 如果指定元素的类型与此 set 不兼容(可选)
NullPointerException - 如果指定的元素为 null,并且此 set 不允许 null 元素(可选)
UnsupportedOperationException - 如果此 set 不支持 remove 操作
set.add("a");
set.add("b");
set.add("c");
set.add("d");
System.out.println(set);
set.remove("c");
System.out.println(set);
另外,一般对应hash算法的集合,如果修改hash值,那就移除不了了.