java.util.concurrent.ConcurrentSkipListSet.spliterator()方法是Java中的内置函数,该函数在该集合的各个元素之间返回弱统一的Spliterator。
用法:
ConcurrentSkipListSet.spliterator()
参数:该函数不接受任何参数。
返回值:该函数在该集合的元素之间返回一个分隔符。
以下示例程序旨在说明ConcurrentSkipListSet.spliterator()方法:
示例1:
// Java Program Demonstrate Spliterator()
// method of ConcurrentSkipListSet
import java.util.Spliterator;
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetSpliteratorExample1 {
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("best!!");
// spliterator split and iterate
// the split parts in parallel
Spliterator<String> str = set.spliterator();
// performs the action for each remaining element
str.forEachRemaining(
(n) -> {
String lc = n.toUpperCase();
System.out.println(" Lower case = " + n);
System.out.println(" Upper case = " + lc);
System.out.println();
});
}
}
输出:
Lower case = Gfg Upper case = GFG Lower case = best!! Upper case = BEST!! Lower case = is Upper case = IS
示例2:
// Java Program Demonstrate Spliterator()
// method of ConcurrentSkipListSet
import java.util.Spliterator;
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetSpliteratorExample2 {
public static void main(String[] args)
{
// Initializing the set
ConcurrentSkipListSet<Character> set =
new ConcurrentSkipListSet<Character>();
// Adding elements to this set
for (char ch = 'A'; ch <= 'Z'; ch++) {
set.add(ch);
}
// Printing elements in the set
System.out.print("The elements in the set are : ");
// spliterator split and iterate
// the split parts in parallel
Spliterator<Character> str = set.spliterator();
// if element exists tryAdvance() will perform action
while (str.tryAdvance((n) -> System.out.print(n + " ")))
;
}
}
输出:
The elements in the set are : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
相关用法
- Java LinkedList spliterator()用法及代码示例
- Java ConcurrentLinkedQueue spliterator()用法及代码示例
- Java PriorityQueue spliterator()用法及代码示例
- Java CopyOnWriteArraySet spliterator()用法及代码示例
- Java HashSet spliterator()用法及代码示例
- Java ArrayDeque spliterator()用法及代码示例
- Java ArrayList spliterator()用法及代码示例
- Java LinkedTransferQueue spliterator()用法及代码示例
- Java CopyOnWriteArrayList spliterator()用法及代码示例
- Java LinkedBlockingDeque spliterator()用法及代码示例
- Java PriorityBlockingQueue spliterator()用法及代码示例
- Java ArrayBlockingQueue spliterator()用法及代码示例
- Java ConcurrentSkipListSet first()用法及代码示例
- Java ConcurrentSkipListSet last()用法及代码示例
- Java ConcurrentSkipListSet add()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 ConcurrentSkipListSet spliterator() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。