import java.util.LinkedList; import java.util.Iterator; public class ExampleLinkedList { public static void main(String[] args) { LinkedListlist = new LinkedList<>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); Iterator descendingIterator = list.descendingIterator(); while(descendingIterator.hasNext()) { System.out.println(descendingIterator.next()); } } }
import java.util.LinkedList; import java.util.ListIterator; public class ExampleLinkedList { public static void main(String[] args) { LinkedListIn this example, we create a LinkedList of integers, add elements to it, and then create a ListIterator using the listIterator() method, passing in the size of the list as the starting index. We then use a while loop to iterate through the elements of the list in reverse order. Both examples use the java.util package, specifically the LinkedList class.list = new LinkedList<>(); list.add(1); list.add(2); list.add(3); ListIterator descendingIterator = list.listIterator(list.size()); while(descendingIterator.hasPrevious()) { System.out.println(descendingIterator.previous()); } } }