这个 下降迭代器() 方法 LinkedBlockingDeque 按相反顺序返回此数据块中元素的迭代器。元素将按从最后一个(尾部)到第一个(头部)的顺序返回。返回的迭代器是“弱一致”迭代器。
null
语法:
public Iterator descendingIterator()
参数: 此方法不接受任何参数。
返回: 这个方法返回一个迭代器,迭代器按相反的顺序遍历这个数据块中的元素。
下面的程序演示了 LinkedBlockingDeque :
项目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
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END