栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Collections Set方法 - Java记录

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Collections Set方法 - Java记录

	public static void main(String[] args) {
		// HashSet
		HashSet hs = new HashSet();
		System.out.print("集合中是否不含元素:");
		System.out.println(hs.isEmpty());
		hs.add(112);
		hs.add(118);
		hs.add(123);
		hs.add(456);
		hs.add(231);
		System.out.print("集合中是否存在123:");
		System.out.println(hs.contains(123));
		System.out.println("----for...each循环遍历set集合----");
		for (Integer str : hs) {
			System.out.println(str);
		}
		System.out.println("----删除123----");
		hs.remove(123);
		System.out.println("----迭代器遍历HashSet集合----");
		Iterator it = hs.iterator();
		while (it.hasNext()) {
			int str = it.next();
			System.out.println(str);
		}
		// TreeSet
		TreeSet ts = new TreeSet<>();
		ts.add(112);
		ts.add(118);
		ts.add(456);
		ts.add(123);
		ts.add(231);
		System.out.println("----迭代器遍历TreeSet集合----");
		Iterator ti = ts.iterator();
		while (ti.hasNext()) {
			int str = ti.next();
			System.out.println(str);
		}
		System.out.println("----TreeSet集合已经自动排序----");
	}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/845787.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号