📌  相关文章
📜  Java中的 ConcurrentSkipListSet descendingIterator() 方法

📅  最后修改于: 2022-05-13 01:55:33.932000             🧑  作者: Mango

Java中的 ConcurrentSkipListSet descendingIterator() 方法

Java .util.concurrent.ConcurrentSkipListSetdescendingIterator()方法是Java中的一个内置函数,用于按降序返回此集合中元素的迭代器。

句法:

ConcurrentSkipListSet.descendingIterator()

返回值:该函数以降序返回此集合中元素的迭代器。

下面的程序说明了 ConcurrentSkipListSet.descendingIterator() 方法:

方案一:

// Java Program Demonstrate descendingIterator()
// method of ConcurrentSkipListSet 
  
import java.util.Iterator;
import java.util.concurrent.ConcurrentSkipListSet;
  
class ConcurrentSkipListSetIteratorExample1 {
    public static void main(String[] args)
    {
  
        // Initializing the set
        ConcurrentSkipListSet
            set = new ConcurrentSkipListSet();
  
        // Adding elements to this set
        set.add("Gfg");
        set.add("is");
        set.add("fun!!");
  
        // Returns an iterator over the elements
        Iterator iterator = set.descendingIterator();
  
        // Printing the elements of the set
        while (iterator.hasNext())
            System.out.print(iterator.next() + " ");
    }
}
输出:
is fun!! Gfg

方案二:

// Java Program Demonstrate descendingIterator()
// method of ConcurrentSkipListSet 
  
import java.util.Iterator;
import java.util.concurrent.ConcurrentSkipListSet;
  
class ConcurrentSkipListSetIteratorExample1 {
    public static void main(String[] args)
    {
  
        // Initializing the set
        ConcurrentSkipListSet
            set = new ConcurrentSkipListSet();
  
        // Adding elements to this set
        set.add(10);
        set.add(15);
        set.add(20);
        set.add(25);
  
        // Returns an iterator over the elements
        Iterator iterator = set.descendingIterator();
  
        // Printing the elements of the set
        while (iterator.hasNext())
            System.out.print(iterator.next() + " ");
    }
}
输出:
25 20 15 10

参考: https: Java/util/concurrent/ConcurrentSkipListSet.html#descendingIterator–