ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 以反向顺序迭代`LinkedList` > 原文: [https://beginnersbook.com/2014/08/iterate-a-linkedlist-in-reverse-sequential-order-java/](https://beginnersbook.com/2014/08/iterate-a-linkedlist-in-reverse-sequential-order-java/) #### 描述 使用 LinkedList 类的 descendingIterator()方法以相反的顺序迭代链表的程序。 #### 程序 ```java import java.util.LinkedList; import java.util.Iterator; class LinkedListDemo { public static void main(String[] args) { // create a LinkedList LinkedList<String> list = new LinkedList<String>(); // Adding elements to the LinkedList list.add("Element1"); list.add("Element2"); list.add("Element3"); list.add("Element4"); // Displaying LinkedList elements System.out.println("LinkedList elements: "+list); /* public Iterator<E> descendingIterator(): Returns an * iterator over the elements in this list in reverse * sequential order. The elements will be returned in * order from last (tail) to first (head). */ Iterator it = list.descendingIterator(); // Displaying list in reverse order System.out.println("Elements in Reverse Order:"); while (it.hasNext()) { System.out.println(it.next()); } } } ``` **输出:** ```java LinkedList elements: [Element1, Element2, Element3, Element4] Elements in Reverse Order: Element4 Element3 Element2 Element1 ```