Java 中的 ConcurrentSkipListSet 下行 terator()方法
原文:https://www . geeksforgeeks . org/concurrentskiplistset-dependingiterator-method-in-Java/
java . util . concurrentskiplistset的dependingiterator()方法是 Java 中的内置函数,用于以降序返回该集合中元素的迭代器。
语法:
ConcurrentSkipListSet.descendingIterator()
返回值:函数以降序返回该集合中元素的迭代器。
下面的程序说明了 ConcurrentSkipListSet .下行畸胎()方法:
程序 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
程序二:
// 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
版权属于:月萌API www.moonapi.com,转载请注明出处