当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ConcurrentSkipListSet descendingIterator()用法及代码示例


java.util.concurrent.ConcurrentSkipListSet的descendingIterator()方法是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-



相关用法


注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 ConcurrentSkipListSet descendingIterator() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。