2021.03.23
第37次记录:
代码演示1:
public class HashSetTest01 {
public static void main(String[] args) {
//演示HashSet集合特点
Set<String> strs = new HashSet<String>();
strs.add("hello");
strs.add("he11o2");
strs.add("he11o3");
strs.add("he11o4");
for (String s:strs){
System.out.println(s);
}
}
}
输出结果:
hello
he11o4
he11o2
he11o3
代码演示2:
public class TreeSetTest01 {
public static void main(String[] args) {
Set<String> strs = new TreeSet<String>();
strs.add("a");
strs.add("z");
strs.add("b");
strs.add("x");
strs.add("c");
strs.add("y");
for (String s:strs){
System.out.println(s);
}
}
}
输出结果:
a
b
c
x
y
z