LinkedBlockingDeque的descendingIterator()方法以相反的順序在此雙端隊列中的元素上返回迭代器。元素將按從last(tail)到first(head)的順序返回。返回的迭代器是一個弱一致性迭代器。
用法:
public Iterator descendingIterator()
參數:此方法不接受任何參數。
返回值:此方法以相反的順序在此雙端隊列中的元素上返回迭代器。
以下示例程序旨在說明LinkedBlockingDeque的descendingIterator()方法:
程序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());
}
}
}
輸出:
The iterator values of LinkedBlockingDeque are: 7855642 35658786 5278367 74381793
程序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());
}
}
}
輸出:
The iterator values of LinkedBlockingDeque are: Portal Computer A forGeeks Geeks
相關用法
- Java ConcurrentLinkedDeque descendingIterator()用法及代碼示例
- Java ArrayDeque descendingIterator()用法及代碼示例
- Java ConcurrentSkipListSet descendingIterator()用法及代碼示例
- Java NavigableSet descendingIterator()用法及代碼示例
- Java Deque descendingIterator()用法及代碼示例
- Java LinkedList descendingIterator()用法及代碼示例
- Java TreeSet descendingIterator()用法及代碼示例
- Java LinkedBlockingDeque take()用法及代碼示例
- Java LinkedBlockingDeque add()用法及代碼示例
- Java LinkedBlockingDeque pop()用法及代碼示例
- Java LinkedBlockingDeque contains()用法及代碼示例
- Java LinkedBlockingDeque put()用法及代碼示例
- Java LinkedBlockingDeque removeLastOccurrence()用法及代碼示例
- Java LinkedBlockingDeque equals()用法及代碼示例
- Java LinkedBlockingDeque size()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 LinkedBlockingDeque descendingIterator() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。