import java.util.*;
public class Set1{
static void fill(Set s){
s.addAll(Arrays.asList(
"one two three four five six seven".split("")));
}
public static void test(Set s){
System.out.println(
s.getClass().getName().replaceAll("\\w+\\.",""));
fill(s);fill(s);fill(s);
System.out.println(s);
s.addAll(s);
s.add("one");
s.add("one");
s.add("one");
System.out.println(s);
}
public static void main(String[] args){
test(new HashSet());
test(new TreeSet());
test(new LinkedHashSet());
}
}以上的输出结果是
"HashSet",
"[one,two,five,four,three,seven,six]",
"[one,two,five,four,three,seven,six]",
"s.contains(\"one\"):true",
接下的雷同不打了
我想问的是红色部分是怎么来的 我看不懂 请给我详细讲解 谢谢了
public class Set1{
static void fill(Set s){
s.addAll(Arrays.asList(
"one two three four five six seven".split("")));
}
public static void test(Set s){
System.out.println(
s.getClass().getName().replaceAll("\\w+\\.",""));
fill(s);fill(s);fill(s);
System.out.println(s);
s.addAll(s);
s.add("one");
s.add("one");
s.add("one");
System.out.println(s);
}
public static void main(String[] args){
test(new HashSet());
test(new TreeSet());
test(new LinkedHashSet());
}
}以上的输出结果是
"HashSet",
"[one,two,five,four,three,seven,six]",
"[one,two,five,four,three,seven,six]",
"s.contains(\"one\"):true",
接下的雷同不打了
我想问的是红色部分是怎么来的 我看不懂 请给我详细讲解 谢谢了
我奇怪这条语句:"s.contains(\"one\"):true",
怎么出来的?
1.6.0_21-b07的输出结果:
HashSet
[, f, , e, n, o, h, i, w, v, u, t, s, r, x]
[, f, , e, one, n, o, h, i, w, v, u, t, s, r, x]
TreeSet
[, , e, f, h, i, n, o, r, s, t, u, v, w, x]
[, , e, f, h, i, n, o, one, r, s, t, u, v, w, x]
LinkedHashSet
[, o, n, e, , t, w, h, r, f, u, i, v, s, x]
[, o, n, e, , t, w, h, r, f, u, i, v, s, x, one]
HashSet
不会按你给的顺序排列的
TreeSet
从小到大
s.addAll(Arrays.asList("one two three four five six seven".split("")));
应该是s.addAll(Arrays.asList("one two three four five six seven".split(" ")));
至于出现红色打印结果 ,你可以从eclipse设置上着手, System.erro这个打印是红色
输出结果是
HashSet
[,o,i,w,r,h,u,f,t,n,x,s,v,e]
[,o,one,i,w,r,h,u,f,t,n,x,s,v,e]
以下省略....
请问是怎么计算的