Java Reference
In-Depth Information
Display 15.26
Using a Doubly Linked List with an Iterator (part 2 of 2)
10
System.out.println("List contains:");
11
i.restart( );
12
while (i.hasNext( ))
13
System.out.println(i.next( ));
14
System.out.println( );
15
i.restart( );
16
i.next( );
17
i.next( );
18
System.out.println("Delete " + i.peek( ));
19
i.delete( );
20
System.out.println("List now contains:");
21
i.restart( );
22
while (i.hasNext( ))
23
System.out.println(i.next( ));
24
System.out.println( );
25
i.restart( );
26
i.next( );
27
System.out.println("Inserting socks before " + i.peek( ));
28
i.insertHere("socks");
29
i.restart( );
30
System.out.println("List now contains:");
31
while (i.hasNext( ))
32
System.out.println(i.next( ));
33
System.out.println( );
34
}
35
}
Sample Dialogue
List contains:
coat
orange juice
shoes
Delete shoes
List now contains:
Coat
Orange juice
Inserting socks before orange juice
List now contains:
coat
socks
orange juice
Search WWH ::




Custom Search