Java ConcurrentSkipListSet descendingIterator()方法

Java ConcurrentSkipListSet descendingIterator()方法

java.util.concurrent.ConcurrentSkipListSetdescendingIterator() 方法是Java中的一个内置函数,用于返回该集合中元素的递减迭代器。

语法

ConcurrentSkipListSet.descendingIterator()

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

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

程序1 :

// 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<String>
            set = new ConcurrentSkipListSet<String>();
  
        // Adding elements to this set
        set.add("Gfg");
        set.add("is");
        set.add("fun!!");
  
        // Returns an iterator over the elements
        Iterator<String> iterator = set.descendingIterator();
  
        // Printing the elements of the set
        while (iterator.hasNext())
            System.out.print(iterator.next() + " ");
    }
}

输出。

is fun!! Gfg

程序2

// 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<Integer>
            set = new ConcurrentSkipListSet<Integer>();
  
        // Adding elements to this set
        set.add(10);
        set.add(15);
        set.add(20);
        set.add(25);
  
        // Returns an iterator over the elements
        Iterator<Integer> iterator = set.descendingIterator();
  
        // Printing the elements of the set
        while (iterator.hasNext())
            System.out.print(iterator.next() + " ");
    }
}

输出。

25 20 15 10

参考资料: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#descendingIterator-

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程