* LinkedHashSet继承自HashSet
* 哈希表/链接表
* 1)元素唯一性(哈希表保证)
* 2)有序性(存储和取出一致),链表保证
public class LinkedHashSetDemo {
public static void main(String[] args) {
//创建一个LinkedHashSet集合对象
LinkedHashSet<String>lsh=new LinkedHashSet<String>();
//添加字符串数据
lsh.add("hello");
lsh.add("java");
lsh.add("qwe");
lsh.add("qwe");
lsh.add("javaee");
//遍历
for(String s:lsh) {
System.out.println(s);
}
}
}
* TreeSet基于TreeMap的一个红黑树结构(Red-Black-Tree)
* 其实就是一种二叉树结构
* 根据构造方法:
* 1)自然排序:public TreeSet()
* 2)选择器排序
public class TreeSetDemo {
public static void main(String[] args) {
//创建空参的TreeSet集合对象
TreeSet<Integer>tree=new TreeSet<Integer>();
//添加元素
tree.add(1);
tree.add(56);
tree.add(98);
tree.add(64);
tree.add(23);
tree.add(2);
//增强for
for(Integer i:tree) {
System.out.println(i);
}
}
}