-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01b_linked_list.java
47 lines (38 loc) · 1.29 KB
/
01b_linked_list.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
import java.util.*;
// https://docs.oracle.com/javase/tutorial/collections/interfaces/list.html
class MyCollections {
public static void main(String args[]) {
example_linkedList_string();
}
public static void example_linkedList_string() {
// Create using
// LinkedList <Data Type> variable = new LinkedList <Data Type>();
LinkedList<String> workingDays = new LinkedList<String>();
workingDays.add("Monday");
workingDays.add("Tuesday");
workingDays.add("Wednesday");
workingDays.add("Friday");
// Add to a specific index
workingDays.add(3, "Thursday");
// Iterate over the array list
Iterator itor = workingDays.iterator();
System.out.println("\nWorkdays");
while( itor.hasNext() ) {
System.out.println( itor.next() );
}
// function to check whether the value is in ArrayList
if( workingDays.contains("Saturday") == false) {
System.out.println("Workdays does not conatin Saturday");
} else {
System.out.println("Workdays does conatin Saturday");
}
System.out.println("Clearing the array list...");
workingDays.clear();
// Iterate over the array list
itor = workingDays.iterator();
System.out.println("\nWorkdays");
while( itor.hasNext() ) {
System.out.println( itor.next() );
}
}
}