Wednesday, November 20, 2024
Google search engine
HomeLanguagesJavaLinkedBlockingDeque descendingIterator() method in Java

LinkedBlockingDeque descendingIterator() method in Java

The descendingIterator() method of LinkedBlockingDeque returns an iterator over the elements in this deque in a reverse sequential order. The elements will be returned in order from last(tail) to first(head). The returned iterator is a “weakly consistent” iterator.

Syntax:

public Iterator descendingIterator()

Parameters: This method does not accept any parameter.

Returns: This method returns an iterator over the elements in this deque in a reverse sequential order.

Below programs illustrate descendingIterator() method of LinkedBlockingDeque:

Program 1:




// Java Program Demonstrate descendingIterator()
// method of LinkedBlockingDeque
  
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
  
    {
  
        // create object of LinkedBlockingDeque
        LinkedBlockingDeque<Integer> LBD
            = new LinkedBlockingDeque<Integer>();
  
        // Add numbers to front of LinkedBlockingDeque
        LBD.addFirst(7855642);
        LBD.addFirst(35658786);
        LBD.addFirst(5278367);
        LBD.addFirst(74381793);
  
        // Call descendingIterator() method of LinkedBlockingDeque
        Iterator iteratorVals = LBD.descendingIterator();
  
        // Print elements of iterator
        // created from PriorityBlockingQueue
        System.out.println("The iterator values"
                           + " of LinkedBlockingDeque are:");
  
        // prints the elements using an iterator
        while (iteratorVals.hasNext()) {
            System.out.println(iteratorVals.next());
        }
    }
}


Output:

The iterator values of LinkedBlockingDeque are:
7855642
35658786
5278367
74381793

Program 2:




// Java Program Demonstrate descendingIterator()
// method of LinkedBlockingDeque
// when list is of strings
  
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
  
    {
  
        // create object of LinkedBlockingDeque
        LinkedBlockingDeque<String> LBD
            = new LinkedBlockingDeque<String>();
  
        // Add numbers to front of LinkedBlockingDeque
        LBD.add("Geeks");
        LBD.add("forGeeks");
        LBD.add("A");
        LBD.add("Computer");
        LBD.add("Portal");
  
        // Call iterator() method of LinkedBlockingDeque
        Iterator iteratorVals = LBD.descendingIterator();
  
        // Print elements of iterator
        // created from PriorityBlockingQueue
        System.out.println("The iterator values"
                           + " of LinkedBlockingDeque are:");
  
        // prints the elements using an iterator
        while (iteratorVals.hasNext()) {
            System.out.println(iteratorVals.next());
        }
    }
}


Output:

The iterator values of LinkedBlockingDeque are:
Portal
Computer
A
forGeeks
Geeks

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedBlockingDeque.html#descendingIterator()

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments