-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomework.java
39 lines (28 loc) · 1.19 KB
/
Homework.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
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
public class Homework{
public static void main(String[] args){
/*
LinkedList<String> hello = new LinkedList<String> (); //Step 1
hello.addFirst("Harry"); //Step 2
hello.addLast("Diana"); //Step 3
hello.addFirst("Tom"); //Step 4
System.out.println(hello.removeLast()); //Step 5
System.out.println(hello.removeFirst()); //Step 6
System.out.println(hello.removeLast()); //Step 7
System.out.println('\n');
*/
LinkedList<String> staff = new LinkedList<String> (); //Step 1
ListIterator<String> iterator = staff.listIterator(); //Step 2
iterator.add("Tom"); //Step 3
iterator.add("Diana"); //Step 4
iterator.add("Harry"); //Step 5
System.out.println(staff);
iterator = staff.listIterator(); //Step 6
if (iterator.next().equals("Tom"))
{iterator.remove();} //Step 7
while (iterator.hasNext())
{ System.out.println(iterator.next()); } //Step 8
}
}