-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathListExample.java
More file actions
25 lines (22 loc) · 800 Bytes
/
ListExample.java
File metadata and controls
25 lines (22 loc) · 800 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
package Collections;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class ListExample {
public static void main(String[] args) {
// ArrayList example
List<String> arrayList = new ArrayList<>();
arrayList.add("Apple");
arrayList.add("Banana");
arrayList.add("Cherry");
System.out.println("ArrayList: " + arrayList);
System.out.println("Element at index 1: " + arrayList.get(1));
// LinkedList example
List<String> linkedList = new LinkedList<>();
linkedList.add("Dog");
linkedList.add("Cat");
linkedList.add("Elephant");
System.out.println("LinkedList: " + linkedList);
System.out.println("Element at index 1: " + linkedList.get(1));
}
}