import java.util.LinkedList; import java.util.ListIterator; public class Example { public static void main(String[] args) { LinkedListnumbers = new LinkedList<>(); numbers.add(1); numbers.add(2); numbers.add(3); ListIterator iterator = numbers.listIterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } }
import java.util.LinkedList; import java.util.ListIterator; public class Example { public static void main(String[] args) { LinkedListIn this example, we create a LinkedList of integers and add three elements to it. Then, we create a ListIterator using the listIterator() method and pass the size of the list as an argument to the method. This creates an iterator that starts at the end of the list. We then use the hasPrevious() and previous() methods to print out each element in reverse order. Package library: java.utilnumbers = new LinkedList<>(); numbers.add(1); numbers.add(2); numbers.add(3); ListIterator iterator = numbers.listIterator(numbers.size()); while (iterator.hasPrevious()) { System.out.println(iterator.previous()); } } }