-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListClass.java
More file actions
63 lines (58 loc) · 1.78 KB
/
LinkedListClass.java
File metadata and controls
63 lines (58 loc) · 1.78 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package Framework;
import java.util.*;
public class LinkedListClass {
public static void main(String[] args) {
LinkedList<Integer> AL1 = new LinkedList<>();
AL1.add(100);
AL1.add(0,99);
AL1.add(101);
LinkedList<Integer> AL2 = new LinkedList<>(List.of(102,103,105,106,107));
AL1.addAll(AL2);
AL2.add(0,102);
AL1.removeAll(AL2);
AL1.addAll(AL2);
AL1.add(5,104);
AL1.remove(3);
AL1.set(4,103);
AL1.set(5,104);
AL2.removeAll(AL2);
System.out.println("ArrayList AL1 Size: "+AL1.size());
System.out.println(AL1);
System.out.println(AL2);
AL1.addFirst(98);
AL1.addLast(108);
System.out.println(AL1.peek());
//Loop
/* for(int i=0; i<AL1.size(); i++){
System.out.print(AL1.get(i)+" ");
}
System.out.println();
for (Integer x: AL1) {
System.out.print((++x)+" ");
} */
// Iterator
Iterator<Integer> IL = AL1.iterator();
while(IL.hasNext()){
System.out.print(IL.next()+" ");
}
System.out.println();
//ListIterator Class
ListIterator<Integer> IL1 = AL1.listIterator();
while(IL1.hasNext()){
System.out.print(IL1.next()+" ");
}
System.out.println(IL1.previous());
System.out.println(IL1.previousIndex());
System.out.println(IL1.hasPrevious());
for(Iterator<Integer> IL2 = AL1.iterator();IL2.hasNext();){
System.out.print(IL2.next()+" ");
}
System.out.println();
// AL1.forEach(System.out::println);
AL1.forEach(n->show(n));
}
static void show(int n){
if(n>103)
System.out.print(n+" ");
}
}