-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListEx.java
More file actions
41 lines (34 loc) · 1.09 KB
/
Copy pathArrayListEx.java
File metadata and controls
41 lines (34 loc) · 1.09 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
import java.util.*;
import static java.lang.System.out;
/**
* Created by santosh on 1/29/2017.
*/
public class ArrayListEx {
public static void main(String[] args) {
List<String> stringList = Arrays.asList(new String[]{"Ruthvik","Santosh","Nihanth","Nihanth"});
iterateList(stringList);
// first type of iterating
out.println("\n revers ");
Collections.reverse(stringList);
out.println(stringList);
Set set = new TreeSet();
set.addAll(stringList);
}
public static void iterateList(List<String> stringList){
// first type of iterating
out.println("first type of iteration");
stringList.forEach(out::print);
//second type of iterating
out.println("\n Second type of iteration");
for (String str:stringList){
out.print(str+" ");
}
//third type
out.println("\n thrid type of iteration");
Iterator iterator = stringList.iterator();
while(iterator.hasNext())
{
out.print(iterator.next()+" ");
}
}
}