Method printReversedList
Method printReversedList
(lines 71–80) prints the list backward. Line 73 calls List
method listIterator
with the starting position as an argument (in our case, the last element in the list) to get a bidirectional iterator for the list. List method size returns the number of items in the List
. The while
condition (line 78) calls ListIterator’s hasPrevious method to determine whether there are more elements while traversing the list backward. Line 79 calls ListIterator’s previous method to get the previous element from the list and outputs it to the standard output stream.
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.