-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArrayListTest.java
More file actions
47 lines (34 loc) · 1.1 KB
/
Copy pathArrayListTest.java
File metadata and controls
47 lines (34 loc) · 1.1 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
import java.util.ArrayList;
import java.util.Collections;
import java.util.*;
public class ArrayListTest {
public static void main( String[] args){
System.out.println("Main Ran");
ArrayList<String> cars = new ArrayList<String>();
cars.add("BMW");
cars.add("VOLVO");
cars.add("Maruthi");
System.out.println("cars 1 :"+ cars.get(0));
cars.set(2, "BENZ");
System.out.println("cars :"+ cars);
System.out.println("Array List Size"+ cars.size());
//cars.clear();
//System.out.println("Array List Size"+ cars.size());
for(int i=0; i<cars.size(); i++){
System.out.println("Car Names : "+ cars.get(i));
}
Collections.sort(cars);
for(String i: cars){
System.out.println("car names sorted order : "+ i);
}
//Using Iterator in collection framework
ListIterator iterator = cars.listIterator();
while(iterator.hasNext()){
System.out.println("from iterator : " +iterator.next());
}
//Using iterator to get backword data
while(iterator.hasPrevious()){
System.out.println(iterator.previous());
}
}
}