LinkedHashSet_TreeSet的红黑树结构

* 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);
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值