java.util.concurrent.ConcurrentSkipListSet的descendingSet()方法是Java中的内置函数,该函数返回此集合中包含的元素的逆序视图。降序集由该集支持,因此对该集的更改会反映在降序集中,反之亦然。
用法:
ConcurrentSkipListSet.descendingSet()
返回值:该函数返回NavigableSet,它是此集合的逆序视图。
以下示例程序旨在说明ConcurrentSkipListSet.Set()方法:
示例1:
// Java Program Demonstrate descendingSet()
// method of ConcurrentSkipListSet */
import java.util.NavigableSet;
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(35);
set.add(20);
set.add(25);
// Printing the elements of the set
System.out.println("Contents of the set: " + set);
// Creating a descending set object
NavigableSet<Integer> des_set = set.descendingSet();
// Printing the elements of the descending set
System.out.println("Contents of the descending set: "
+ des_set);
}
}
输出:
Contents of the set: [10, 20, 25, 35] Contents of the descending set: [35, 25, 20, 10]
示例2:演示在降序集中插入元素时原始集的更改的程序。
// Java Program Demonstrate descendingSet()
// method of ConcurrentSkipListSet */
import java.util.NavigableSet;
import java.util.Iterator;
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetIteratorExample2 {
public static void main(String[] args)
{
// Initializing the set
ConcurrentSkipListSet<String>
set = new ConcurrentSkipListSet<String>();
// Adding elements to this set
set.add("bob");
set.add("alex");
set.add("eric");
set.add("chuck");
// Creating a descending object
NavigableSet<String> des_set = set.descendingSet();
// Adding elements to the descending set and also to the set
des_set.add("drake");
des_set.add("fred");
// Printing the elements of the set
System.out.println("Contents of the set: " + set);
// Printing the elements of the descending set
System.out.println("Contents of the descending set: "
+ des_set);
}
}
输出:
Contents of the set: [alex, bob, chuck, drake, eric, fred] Contents of the descending set: [fred, eric, drake, chuck, bob, alex]
相关用法
- Java NavigableSet descendingSet()用法及代码示例
- Java TreeSet descendingSet()用法及代码示例
- Java ConcurrentSkipListSet last()用法及代码示例
- Java ConcurrentSkipListSet add()用法及代码示例
- Java ConcurrentSkipListSet contains()用法及代码示例
- Java ConcurrentSkipListSet first()用法及代码示例
- Java ConcurrentSkipListSet floor()用法及代码示例
- Java ConcurrentSkipListSet equals()用法及代码示例
- Java ConcurrentSkipListSet headSet()用法及代码示例
- Java ConcurrentSkipListSet subSet()用法及代码示例
- Java ConcurrentSkipListSet removeAll()用法及代码示例
- Java ConcurrentSkipListSet pollLast()用法及代码示例
- Java ConcurrentSkipListSet pollFirst()用法及代码示例
- Java ConcurrentSkipListSet spliterator()用法及代码示例
- Java ConcurrentSkipListSet higher()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 ConcurrentSkipListSet descendingSet() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。