1 package bao4;
2 import java.util.*;
3
4 public class Textset
5 {
6
7 public static void main(String[] args)
8 {
9 //HashSet集合
10 HashSet<String> hh=new HashSet<String>();
11 hh.add("aaa");
12 hh.add("bbb");
13 hh.add("ccc");
14 hh.add("ddd");
15 //不能添加重复数据
16 hh.add("aaa");
17 //集合长度
18 System.out.println("集合的长度"+hh.size());
19 //遍历
20 for(String i:hh)
21 {
22 System.out.println(i);
23 }
24 //判断是否存在
25 hh.contains("aaa");
26 //清除
27 hh.clear();
28 //移除
29 hh.remove("bbb");
30
31 //TreeSet集合最大特点可以把数据进行排序
32 TreeSet<Integer> tt=new TreeSet<Integer>();
33
34 tt.add(134);
35 tt.add(67);
36 tt.add(13);
37 tt.add(434);
38 tt.add(334);
39 tt.add(234);
40 for(Integer i:tt)
41 {
42 System.out.println(i);
43 }
44 }
45
46
47 }