1.定义: Set<Integer>set = new TreeSet<Integer>(); 注意: TreeSet 是二差树实现的,Treeset中的数据是自动排好序的,不允许放入null值。 HashSet 是哈希表实现的,HashSet中的数据是无序的,可以放入null,但只能放入一个null,两者中的值都不能重复,就如数据库中唯一约束。 2.
add( ) 向集合中添加元素 clear( ) 去掉集合中所有的元素 contains( ) 判断集合中是否包含某一个元素 isEmpty( ) 判断集合是否为空 remove( ) 从集合中去掉特定的对象 size( ) 返回集合的大小 3.Set遍历: 法一: for(int x:set) { System.out.println(x); } 法二: for(Iterator it=set.iterator();it.hasNext();) { System.out.println(it.next()); }
util之Set
猜你喜欢
转载自www.cnblogs.com/qdu-lkc/p/12207359.html
今日推荐
周排行