JDK之SET

来源:互联网 发布:mac搜索文件命令 编辑:程序博客网 时间:2024/06/15 12:58

Set接口继承自Collection接口,Set接口跟Collection接口拥有一样的方法定义。但是,Set中不允许出现重复的元素。

//返回集合中元素的个数

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 removeAll(Collection<?> c);

//只保留指定集合中包含的元素

boolean retainAll(Collection<?> c);

//移除集合中所有的元素

 void clear();

//将集合与指定对象进行比较

boolean equals(Object o);

//返回集合的hashcode值

int hashCode();
原创粉丝点击