El método descendingIterator(E e) de la interfaz Deque devuelve un iterador sobre los elementos de esta deque en un orden secuencial inverso. Los elementos se devolverán en orden desde el último (cola) hasta el primero (cabeza). El iterador devuelto es un iterador «débilmente coherente».
Sintaxis:
Iterator descendingIterator()
Parámetros: Este método no acepta ningún parámetro.
Valor devuelto: este método devuelve un iterador sobre los elementos de este deque en una secuencia adecuada
Los siguientes programas ilustran el método descendingIterator() en Java:
Programa 1: Con la ayuda de LinkedList .
// Java code to illustrate descendingIterator() // method of Deque in Java import java.util.*; public class GFG { public static void main(String args[]) { // Creating an empty Deque Deque<String> de_que = new LinkedList<String>(); // Use add() method to add elements into the Queue de_que.add("Welcome"); de_que.add("To"); de_que.add("Geeks"); de_que.add("4"); de_que.add("Geeks"); // Call iterator() method of deque Iterator iteratorVals = de_que.iterator(); // Print elements of iterator // created from PriorityBlockingQueue System.out.println("The iterator values" + " of deque are:"); // prints the elements using an iterator while (iteratorVals.hasNext()) { System.out.println(iteratorVals.next()); } } }
The iterator values of deque are: Welcome To Geeks 4 Geeks
Programa 2:
// Java code to illustrate descendingIterator() // method of Deque in Java import java.util.*; public class GFG { public static void main(String args[]) { // Creating an empty Deque Deque<Integer> de_que = new LinkedList<Integer>(); // Use add() method to add elements into the Queue de_que.add(10); de_que.add(15); de_que.add(30); de_que.add(20); de_que.add(5); // Call iterator() method of deque Iterator iteratorVals = de_que.iterator(); // Print elements of iterator // created from PriorityBlockingQueue System.out.println("The iterator values" + " of deque are:"); // prints the elements using an iterator while (iteratorVals.hasNext()) { System.out.println(iteratorVals.next()); } } }
The iterator values of deque are: 10 15 30 20 5
Programa 3: Con la ayuda de ArrayDeque .
// Java code to illustrate descendingIterator() // method of Deque in Java import java.util.*; public class GFG { public static void main(String args[]) { // Creating an empty Deque Deque<String> de_que = new ArrayDeque<String>(); // Use add() method to add elements into the Queue de_que.add("Welcome"); de_que.add("To"); de_que.add("Geeks"); de_que.add("4"); de_que.add("Geeks"); // Call iterator() method of deque Iterator iteratorVals = de_que.iterator(); // Print elements of iterator // created from PriorityBlockingQueue System.out.println("The iterator values" + " of deque are:"); // prints the elements using an iterator while (iteratorVals.hasNext()) { System.out.println(iteratorVals.next()); } } }
The iterator values of deque are: Welcome To Geeks 4 Geeks
Programa 4: Con la ayuda de LinkedBlockingDeque .
// Java code to illustrate descendingIterator() // method of Deque in Java import java.util.*; import java.util.concurrent.LinkedBlockingDeque; public class GFG { public static void main(String args[]) { // Creating an empty Deque Deque<String> de_que = new LinkedBlockingDeque<String>(); // Use add() method to add elements into the Queue de_que.add("Welcome"); de_que.add("To"); de_que.add("Geeks"); de_que.add("4"); de_que.add("Geeks"); // Call iterator() method of deque Iterator iteratorVals = de_que.iterator(); // Print elements of iterator // created from PriorityBlockingQueue System.out.println("The iterator values" + " of deque are:"); // prints the elements using an iterator while (iteratorVals.hasNext()) { System.out.println(iteratorVals.next()); } } }
The iterator values of deque are: Welcome To Geeks 4 Geeks
Programa 5: Con la ayuda de ConcurrentLinkedDeque .
// Java code to illustrate descendingIterator() // method of Deque in Java import java.util.*; import java.util.concurrent.ConcurrentLinkedDeque; public class GFG { public static void main(String args[]) { // Creating an empty Deque Deque<String> de_que = new ConcurrentLinkedDeque<String>(); // Use add() method to add elements into the Queue de_que.add("Welcome"); de_que.add("To"); de_que.add("Geeks"); de_que.add("4"); de_que.add("Geeks"); // Call iterator() method of deque Iterator iteratorVals = de_que.iterator(); // Print elements of iterator // created from PriorityBlockingQueue System.out.println("The iterator values" + " of deque are:"); // prints the elements using an iterator while (iteratorVals.hasNext()) { System.out.println(iteratorVals.next()); } } }
The iterator values of deque are: Welcome To Geeks 4 Geeks
Referencia: https://docs.oracle.com/javase/8/docs/api/java/util/Deque.html#descendingIterator–