Java Reference
In-Depth Information
System.out.println(staff.removefirst());
System.out.println(staff.removeLast());
΢ Exercise R15.4. Explain what the following code prints. Draw pictures of
the linked list and the iterator position after each step.
LinkedList<String> staff = new
LinkedList<String>();
ListIterator<String>
iterator = staff.listIterator();
iterator.add(ÐTomÐ);
iterator. add(ÐDickÑ);
iterator.add(ÐHarryÑ);
iterator = staff.listIterator();
if (iterator.next() .equals(ÐTomÑ))
iterator.remove();
while (iterator.hasNext())
System.out.println(iterator.next());
΢ Exercise R15.5. Explain what the following code prints. Draw pictures of
the linked list and the iterator position after each step.
LinkedList<String> staff = new
LinkedList<String>();
ListIterator<String>
iterator = staff.listIterator();
iterator.add(ÐTomÑ);
iterator.add(ÐDickÑ);
iterator.add(ÐHarryÑ);
iterator = staff.listIterator();
iterator.next();
iterator.next();
iterator.add(ÐRomeoÑ);
iterator.next();
iterator.add(ÐJulietÑ);
iterator = staff.listIterator();
iterator.next();
iterator.remove();
while (iterator.hasNext())
System.out.println(iterator.next());
΢΢Exercise R15.6. The linked list class in the Java library supports
operations addLast and removeLast . To carry out these operations
efficiently, the LinkedList class has an added reference last to the
Search WWH ::




Custom Search