Java 中 LinkedBlockingDeque()方法
原文:https://www . geeksforgeeks . org/linkedblockingreque-dependingiterator-method-in-Java/
的下行迭代器()方法链接了锁定命令并以相反的顺序返回了这个序列中元素的迭代器。元素将按从最后(尾部)到第一(头部)的顺序返回。返回的迭代器是“弱一致”迭代器。
语法:
public Iterator 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
程序二:
// 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
版权属于:月萌API www.moonapi.com,转载请注明出处