目录
HashSet
HashSet底层是HashMap实现的,HashSet不过是对HashMap做了一些简单包装,代码行数总计不到300行
LinkedHashSet
LinkedHashSet是HashSet的子类,实现方法基本和HashSet区别不大,并不是主要的常用方法
SortedSet
//排序方法
Comparator<E> comparator()
//e1到e2指间的元素包含e1,不包含e2
SortedSet<E> subSet(E e1,E e2)
//e之前的元素,不包含e
SortedSet<E> headSet(E e)
//e之后的元素,包含e
SortedSet<E> tailSet(E e)
//取第一个元素
E first()
//取最后一个元素
E last()
//方法遍历
Spliterator<E> spliterator()
NavigableSet
//返回小于e元素的最大邻近元素
E lower(E e)
//返回小于或等于e元素的最大邻近元素
E floor(E e)
//返回大于或等于e元素的最小邻近元素
E ceiling(E e)
//返回大于e元素的最小邻近元素
E higher(E e);
//取出并删除第一个元素
E pollFirst();
//取出并删除最后一个元素
E pollLast();
//返回fromElement与toElement之间所有的元素,包含fromElement,不包含toElement
SortedSet<E> subSet(E fromElement, E toElement);
//返回fromElement与toElement之间所有的元素,如果fromInclusive或toInclusive为true
//,返回包含fromElement或toElement,反之不包含
NavigableSet<E> subSet(E fromElement, boolean fromInclusive,
E toElement, boolean toInclusive);
//返回toElement之前所有的元素,不包含toElement
SortedSet<E> headSet(E toElement);
//返回toElment之前所有的元素,如果inclusive为true,则包含,否则不包含
NavigableSet<E> headSet(E toElement, boolean inclusive);
//返回fromElement之后的所有元素,包含fromElement
SortedSet<E> tailSet(E fromElement);
//返回fromElement之后的所有元素,如果inclusive为true,则包含,否则不包含
NavigableSet<E> tailSet(E fromElement, boolean inclusive);
//返回集合反序列表
NavigableSet<E> descendingSet();
TreeSet
TreeSet是基于TreeMap实现的有序,没有重复元素,非线程安全的集合,有两种排序方式,自然排序和自定义排序
基本使用方法参考:
https://www.cnblogs.com/Tony-cheen/p/5681831.html
concurrentSkipListSet
TreeSet是基于ConcurrentNavigableMap实现的有序,没有重复元素,线程安全的集合,两种排序方式自然排序与自定义排序,都只用到了key-value中的key存储
实例方法参考:
https://www.cnblogs.com/skywang12345/p/3498634.html
CopyOnWriteArraySet
CopyOnWriteArraySet是基于动态数组CopyOnWriteArrayList实现的,也是线程安全的集合
实例方法参考: