This Java Example shows how to Iterate through the element of the Deque object in java using descendingIterator.
IterateThrough Element Using descendingIterator Java Deque Example
This Java Example shows how to Iterate through the element of the Deque object in java using descendingIterator. To iterate the Deque object we use hasNext() and next() methods of descendingIterator to iterate through the elements. descendingIterator iterate through element in the backword direction.
Example: DescendingItratorDeque.java
package devmanuals.com; import java.util.*; public class DescendingItratorDeque { public static void main(String args[]) { Dequequeue = new ArrayDeque (); queue.add("A"); queue.add("B"); queue.add("C"); queue.add("D"); Iterator itr = queue.descendingIterator(); System.out.println("The Deque elements in farword direction: " + queue); System.out.println("The Deque elements in backword direction : "); while (itr.hasNext()) { System.out.println(itr.next()); } } }
Output:
The Deque elements in farword direction: [A, B, C, D]
The Deque elements in backword direction : |
[ 0 ] Comments