-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForTest.java
More file actions
55 lines (41 loc) · 1.16 KB
/
Copy pathForTest.java
File metadata and controls
55 lines (41 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package collection.java1;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
public class ForTest {
@Test
public void test1(){
Collection coll = new ArrayList();
coll.add(123);
coll.add(new String("Alex"));
coll.add("collection");
Date date = new Date();
coll.add(date);
coll.add(new Person("Coco", 24));
// for(集合元素的类型 局部变量 : 几个对象)
// for( O o : collection) still uses iterator principle behind
for(Object obj: coll){
System.out.println(obj);
}
}
@Test
public void test2(){
String[] str = new String[]{"MM", "MM", "MM"};
// foreach loop
for (String s : str){
s = "GG";
}
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
}
System.out.println("\n-----------");
// for loop
for (int i = 0; i < str.length; i++) {
str[i] = "GG";
}
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
}
}
}