-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforeach.java
More file actions
33 lines (27 loc) · 843 Bytes
/
foreach.java
File metadata and controls
33 lines (27 loc) · 843 Bytes
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
import java.util.ArrayList;
public class foreach{
public static void main(){
// # 1
System.out.println("#1");
String animals[] = {"cat", "dog", "Racoon", "mouse"};
for (String i : animals){
System.out.println(i);
}
// # 2
System.out.println("#2");
String name = "Ishant";
/** for (char i : name){ ##### for-each cannot be implemented on strings only arrays
System.out.println(i);
} */
// # 3
System.out.println("#3");
ArrayList<String> anim = new ArrayList<String>();
anim.add("kutta");
anim.add("billi");
anim.add("dorimon");
anim.add("Chuha");
for (String i : anim){
System.out.println(i);
}
}
}