java是开源的,可以直接看源码。
而且对于一个java程序员来说,JDK里面的集合框架是必看的。
--------- 答案被忽略了,因此新增点儿内容(2014年11月6日) ---------------
HashSet 源码:
定义
public class HashSet
extends AbstractSet
implements Set, Cloneable, java.io.Serializable
HashSet 内部使用了 HashMap:
private transient HashMap map;
如果使用一个已经有的集合来初始化 HashSet:
/**
* Constructs a new set containing the elements in the specified
* collection. The HashMap is created with default load factor
* (0.75) and an initial capacity sufficient to contain the elements in
* the specified collection.
*
* @param c the collection whose elements are to be placed into this set
* @throws NullPointerException if the specified collection is null
*/
public HashSet(Collection extends E> c) {
map = new Has