forked from coder2hacker/Explore-open-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayListDemo.java
66 lines (38 loc) · 1.44 KB
/
ArrayListDemo.java
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
56
57
58
59
60
61
62
63
64
65
66
package collectionsframework;
import java.util.ArrayList;
import java.util.Iterator;
public class ArrayListDemo {
public static void main(String[] args) {
// instantiate an array list
ArrayList<String> countriesList = new ArrayList<String>(); // default size 10
/* Some important method
* clear() contains(Object o) get(int index) indexOf(Object o) isEmpty()
* remove(int index) remove(Object o) removeRange(int fromIndex, int toIndex)
* set(int index, E element) toArray()
*/
countriesList.add("India");
countriesList.add("Bhutan");
countriesList.add("France");
countriesList.add("Usa");
countriesList.add(4, "Egypt");
countriesList.add(5, "Spain");
countriesList.add(6, "Canda");
countriesList.add(7, "oman");
countriesList.add(8, "Uk");
countriesList.add(9,"Zimbambe");
countriesList.add("Mexico");
//countiesList.add(new Employee // genric
// obtain the iterator
Iterator<String> itr = countriesList.iterator();
while(itr.hasNext())
System.out.println(itr.next());
System.out.println("Printing Friends list");
ArrayList<String> friendsList = new ArrayList<String>();
friendsList.add("Shbham");
friendsList.add("Samu");
friendsList.add("Sudhir");
Iterator<String> itr2 = friendsList.iterator();
while(itr2.hasNext())
System.out.println(itr2.next());
}
}