Hashset

public class SetTest {

public static void main(String[] args) {
//HashSet:哈希表是通过使用称为散列法的机制来存储信息
//元素并没有以某种特定顺序来存放;
HashSet<String> hs = new HashSet<String>();
hs.add("B");
hs.add("A");
hs.add("A");
hs.add("D");
hs.add("E");
hs.add("C");
hs.add("F");
hs.add("F");
System.out.println("HashSet 顺序: "+hs);
//TreeSet:提供一个使用树结构存储Set接口的实现,
//对象以升序顺序存储,访问和遍历的时间很快。
TreeSet<String> ts = new TreeSet<String>();
ts.add("B");
ts.add("D");
ts.add("E");
ts.add("A");
ts.add("A");
ts.add("A");
ts.add("A");
ts.add("C");
ts.add("F");
System.out.println("TreeSet 顺序: "+ts);
}

原文地址:https://www.cnblogs.com/zaoxi11/p/6026383.html