-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopingThroughArraylist.java
More file actions
33 lines (26 loc) · 991 Bytes
/
LoopingThroughArraylist.java
File metadata and controls
33 lines (26 loc) · 991 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
package loopingthrougharraylist;
import java.util.ArrayList;
public class LoopingThroughArraylist {
public static void main(String[] args) {
//there are four ways to loop through arraylist
//for loop,enhanced for loop,while loop,iterator
ArrayList<String> arraylist=new ArrayList<String>();
//adding value to the arraylist
arraylist.add("Shakil");
arraylist.add("Jahid");
arraylist.add("Rashed");
arraylist.add("Sagor");
arraylist.add("Faisal");
arraylist.add("koushik");
arraylist.add("Shuvo");
//for looping
for(int counter=0;counter<arraylist.size();counter++){
System.out.println("Name is :"+arraylist.get(counter));
}
System.out.println("\n\n");
//enhanced for looping
for(String name:arraylist){
System.out.println("Name is :"+name);
}
}
}