-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListDemo.java
More file actions
28 lines (24 loc) · 820 Bytes
/
ArrayListDemo.java
File metadata and controls
28 lines (24 loc) · 820 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
import java.util.*;
class ArrayListDemo
{
public static void main(String args[])
{
ArrayList<String> list = new ArrayList<String>();
list.add("Hello");
list.add("World");
list.add("Java");
list.add("Programming");
System.out.println("ArrayList: " + list);
// Accessing elements
System.out.println("First element: " + list.get(0));
System.out.println("Second element: " + list.get(1));
// Removing an element
list.remove(2);
System.out.println("After removing element at index 2: " + list);
// Iterating through the ArrayList
System.out.println("Iterating through the ArrayList:");
for (String str : list) {
System.out.println(str);
}
}
}