Deque descendingIterator() Method in Java Last Updated : 01 Dec, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The descendingIterator() method of the Deque Interface returns an iterator over the elements in this deque in reverse order. The elements will be returned from the last to the first order. This can be used with any class implementing the Deque Interface like LinkedList, ArrayDeque, LinkedBlockingDeque, etc.Syntax:Iterator descendingIterator()Example 1: Here, we are using the LinkedList as Deque. Java // Java program to show the use of Deque // descendingIterator() method import java.util.*; public class GFG { public static void main(String[] args) { // Creating an Empty Deque Deque<Integer> dq = new LinkedList<>(); // Adding elements dq.add(1); dq.add(2); dq.add(3); dq.add(4); // Using descendingIterator() method to // get reverse order of elements Iterator<Integer> iterator = dq.descendingIterator(); // Printing elements in reverse order while (iterator.hasNext()) { System.out.println(iterator.next()); } } } Output4 3 2 1 Example 2: Here, we are using the ArrayDeque as Deque. Java // Java program to show the use of Deque // descendingIterator() method import java.util.*; public class GFG { public static void main(String[] args) { // Creating an Empty Deque Deque<String> dq = new ArrayDeque<>(); // Adding elements dq.add("Hello"); dq.add("Geeks"); dq.add("How Are"); dq.add("You"); // Using descendingIterator() method to // get reverse order of elements Iterator<String> iterator = dq.descendingIterator(); // Printing elements in reverse order while (iterator.hasNext()) { System.out.println(iterator.next()); } } } OutputYou How Are Geeks Hello Comment More infoAdvertise with us Next Article Deque element() method in Java G gopaldave Follow Improve Article Tags : Misc Java Java - util package Java-Functions java-deque +1 More Practice Tags : JavaMisc Similar Reads Deque Interface in Java Deque Interface present in java.util package is a subtype of the queue interface. The Deque is related to the double-ended queue that supports adding or removing elements from either end of the data structure. It can either be used as a queue(first-in-first-out/FIFO) or as a stack(last-in-first-out/ 9 min read Deque add() method in Java The add(E e) method of Deque Interface inserts the element passed in the parameter to the end of the Deque if there is space. If the Deque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. The function returns true on successful insertion. Syntax:  bool 4 min read Deque addFirst() method in Java with Examples The addFirst(E e) method of Deque Interface inserts the element passed in the parameter to the front of the Deque if there is space. If the Deque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. The function returns true on successful insertion. Syntax: 4 min read Deque addLast() method in Java The addLast(E e) method of Deque Interface inserts the element passed in the parameter to the end of the Deque if there is space. If the Deque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. The function returns true on successful insertion. Syntax: bo 4 min read Deque contains() method in Java The contains(E e) method of Deque Interface check for the presence of the element e in the Deque container. If the Deque contains one occurrence of the element, then it returns true else it returns false. Syntax: boolean contains(Object o) Parameters: This method accepts a mandatory parameter o whic 5 min read Deque descendingIterator() Method in Java The descendingIterator() method of the Deque Interface returns an iterator over the elements in this deque in reverse order. The elements will be returned from the last to the first order. This can be used with any class implementing the Deque Interface like LinkedList, ArrayDeque, LinkedBlockingDeq 2 min read Deque element() method in Java The element() method of Deque Interface returns the element at the front the container. It does not deletes the element in the container. This method returns the head of the Deque. The method throws an exception when the Deque is empty. Syntax:  E element() Parameters: This method does not accepts 3 min read Deque getFirst() method in Java The getFirst() method of Deque Interface returns the first element or the head of the Deque. It does not deletes the element. It throws an exception when the Deque is empty. Syntax:  E getFirst() Parameters: This method does not accepts any parameter.Returns: This method returns the first element o 3 min read Deque getLast() method in Java The getLast() method of Deque Interface returns the last element or the tail of the Deque. It does not deletes the element. It throws an exception when the Deque is empty. Syntax: E getLast() Parameters: This method does not accepts any parameter. Returns: This method returns the last element or the 3 min read Deque iterator() method in Java The iterator() method of Deque Interface returns an iterator over the elements in this deque in a proper sequence. The elements will be returned in order from first (head) to last (tail). The returned iterator is a âweakly consistentâ iterator. Syntax: Iterator iterator() Parameters: This method doe 3 min read Like