Skip to content

Commit b6cc7d5

Browse files
committed
1. Collections 的使用更新
#bysocket
1 parent 50cd6f7 commit b6cc7d5

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/org/javacore/collection/util/CollectionsT.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,33 @@ public class CollectionsT{
2828
public static void main(String[] args){
2929
// 测试集合工具类Sort方法
3030
testSort();
31+
testAddAll();
3132
}
3233

3334
/**
3435
* 测试集合工具类Sort方法
3536
*/
36-
private static void testSort(){
37-
List<Integer> teams = new ArrayList<Integer>();
38-
teams.add(1);
39-
teams.add(3);
40-
teams.add(2);
41-
teams.add(4);
42-
// 调用集合工具类Sort方法
43-
Collections.sort(teams);
44-
45-
System.out.println("Teams:");
46-
System.out.print("\t" + teams + "\n");
47-
}
37+
private static void testSort(){
38+
List<Integer> list = new ArrayList<Integer>();
39+
list.add(1);
40+
list.add(3);
41+
list.add(2);
42+
list.add(4);
43+
// 调用集合工具类Sort方法
44+
Collections.sort(list);
45+
46+
System.out.println("list sorted:");
47+
System.out.print("\t" + list + "\n");
48+
}
49+
50+
private static void testAddAll() {
51+
List<String> list = new ArrayList<>();
52+
list.add("s2");
53+
list.add("s4");
54+
list.add("s1");
55+
list.add("s3");
56+
System.out.println(list);
57+
Collections.addAll(list, "s5","s7",null,"s9");
58+
System.out.println(list);
59+
}
4860
}

0 commit comments

Comments
 (0)