This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the null element.
HashSet实现了Set接口,其本质是一个HashMap,只使用到了HashMap的key值,value是一个固定的值。对HashSet进行迭代的时候,不能保证其迭代的顺序,其允许添空值。
简单例子如下:
@SuppressWarnings(value = { "all" })
public class TestHashSet {
public static void main(String[] args) {