Java 集合框架分析:Set(1)
2016-10-04 13:59
337 查看
相关文章:
Java 集合框架分析:Set
http://blog.csdn.net/youyou1543724847/article/details/52733723
Java 集合框架分析:LinkedList
http://blog.csdn.net/youyou1543724847/article/details/52734935
Java 集合框架分析:DelayQueue
http://blog.csdn.net/youyou1543724847/article/details/52176504
Java 集合框架分析:ArrayBlockingQueue
http://blog.csdn.net/youyou1543724847/article/details/52174308
Java 集合框架分析:ArrayDeque
http://blog.csdn.net/youyou1543724847/article/details/52170026
Java 集合框架分析:PriorityBlockingQueue
http://blog.csdn.net/youyou1543724847/article/details/52166985
Java 集合框架分析:JAVA Queue源码分析
http://blog.csdn.net/youyou1543724847/article/details/52164895
Java 集合框架分析:关于Set,Map集合中元素判等的方式
http://blog.csdn.net/youyou1543724847/article/details/52733766
Java 集合框架分析:ConcurrentModificationException
http://blog.csdn.net/youyou1543724847/article/details/52733780
Java 集合框架分析:线程安全的集合
http://blog.csdn.net/youyou1543724847/article/details/52734876
Java 集合框架分析:JAVA集合中的一些边边角角的知识
http://blog.csdn.net/youyou1543724847/article/details/52734918
常用的两种set:TreeSet,HashSet
实现:都是基于相应的map接口来的,如TreeSet底层用的TreeMap,HashSet底层用的HashMap。映射到map,key为set中你要放置的量,value为一个全局的object对象(节约空间)
提供常量时间的性能,对于add, remove, contains and size(如果hash函数将元素散开在不同的桶上的话) Iterating over this set requires time proportional to the sum of the HashSet instance’s size (the number of elements) plus the “capacity” of the backing HashMap instance (the number of buckets). Thus, it’s very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important. 在HashSet上的迭代的时间和 hashset实例的大小+容器的capacity大小之和 成正比
Java 集合框架分析:Set
http://blog.csdn.net/youyou1543724847/article/details/52733723
Java 集合框架分析:LinkedList
http://blog.csdn.net/youyou1543724847/article/details/52734935
Java 集合框架分析:DelayQueue
http://blog.csdn.net/youyou1543724847/article/details/52176504
Java 集合框架分析:ArrayBlockingQueue
http://blog.csdn.net/youyou1543724847/article/details/52174308
Java 集合框架分析:ArrayDeque
http://blog.csdn.net/youyou1543724847/article/details/52170026
Java 集合框架分析:PriorityBlockingQueue
http://blog.csdn.net/youyou1543724847/article/details/52166985
Java 集合框架分析:JAVA Queue源码分析
http://blog.csdn.net/youyou1543724847/article/details/52164895
Java 集合框架分析:关于Set,Map集合中元素判等的方式
http://blog.csdn.net/youyou1543724847/article/details/52733766
Java 集合框架分析:ConcurrentModificationException
http://blog.csdn.net/youyou1543724847/article/details/52733780
Java 集合框架分析:线程安全的集合
http://blog.csdn.net/youyou1543724847/article/details/52734876
Java 集合框架分析:JAVA集合中的一些边边角角的知识
http://blog.csdn.net/youyou1543724847/article/details/52734918
常用的两种set:TreeSet,HashSet
实现:都是基于相应的map接口来的,如TreeSet底层用的TreeMap,HashSet底层用的HashMap。映射到map,key为set中你要放置的量,value为一个全局的object对象(节约空间)
TreeSet
看一下源码结构
public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, java.io.Serializable { /** * The backing map. */ private transient NavigableMap<E,Object> m; // Dummy value to associate with an Object in the backing Map private static final Object PRESENT = new Object(); /** * Constructs a set backed by the specified navigable map. */ TreeSet(NavigableMap<E,Object> m) { this.m = m; } /** * Constructs a new, empty tree set, sorted according to the * natural ordering of its elements. All elements inserted into * the set must implement the {@link Comparable} interface. * Furthermore, all such elements must be <i>mutually * comparable</i>: {@code e1.compareTo(e2)} must not throw a * {@code ClassCastException} for any elements {@code e1} and * {@code e2} in the set. If the user attempts to add an element * to the set that violates this constraint (for example, the user * attempts to add a string element to a set whose elements are * integers), the {@code add} call will throw a * {@code ClassCastException}. */ public TreeSet() { this(new TreeMap<E,Object>()); } public TreeSet(Comparator<? super E> comparator) { this(new TreeMap<>(comparator)); }
特性:
基于树的实现,能保证元素的排列顺序,且插入、查找、删除的时间为log(n)HashSet
结构和TreeSet大同小异特性:
基于hash表实现,不保持元素的顺序,(This class implements the Set interface, backed by a hash table (actually a HashMap instance).提供常量时间的性能,对于add, remove, contains and size(如果hash函数将元素散开在不同的桶上的话) Iterating over this set requires time proportional to the sum of the HashSet instance’s size (the number of elements) plus the “capacity” of the backing HashMap instance (the number of buckets). Thus, it’s very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important. 在HashSet上的迭代的时间和 hashset实例的大小+容器的capacity大小之和 成正比
相关文章推荐
- Java 集合框架分析:关于Set,Map集合中元素判等的方式
- Java中集合框架,Collection接口、Set接口、List接口、Map接口,已经常用的它们的实现类,简单的JDK源码分析底层实现
- Java中集合框架,Collection接口、Set接口、List接口、Map接口,已经常用的它们的实现类,简单的JDK源码分析底层实现
- java学习笔记:集合框架之TreeSet
- java学习笔记:集合框架之TreeSet
- Java学习第14天:集合框架零接触和基本理解(List和Set)
- 十六、Java基础---------集合框架之Set
- Java集合的Set、List、Map异同分析
- Java集合总结之Set整体框架
- java中Set集合的遍历及实现类比较分析
- [Java基础] 持有对象(集合框架)-Set-TreeSet
- java中的集合框架Set 、List 、Map
- java核心之集合框架——ArrayList源码分析
- java基础-- 集合框架 之 Set集合
- 黑马程序员_java_集合框架_Collection_List_Set_泛型
- Map、Set、Iterator迭代详解与Java平台的集合框架
- 集合框架源码分析五之LinkedHashMap,LinkedHashSet
- Java 集合框架 性能分析
- 黑马程序员_Java第14天知识总结_集合类(集合框架)_Collection_迭代器_List_Set_HashSet
- 黑马程序员——java基础拾遗之集合框架(一) List 和 Set