Java Vector 类的 spliterator() 方法用于在此列表中的元素上创建后期绑定和 fail-fast 拆分器。
用法
以下是 spliterator() 方法的声明:
public Spliterator<E> spliterator()
参数
此方法不接受任何参数。
返回
spliterator() 方法在列表中的元素上返回一个拆分器。
异常
NA
兼容版本
Java 1.8 及以上
例子1
import java.util.*;
import java.util.stream.Stream;
public class VectorSpliteratorExample1 {
public static void main(String arg[]) {
//Creating an empty vector object
Vector<Integer> v1 = new Vector<Integer>();
//Adding elemnts to the vector
v1.add(10);
v1.add(30);
v1.add(20);
v1.add(40);
//Obtain a Stream to the vector
Stream<Integer> str = v1.stream();
//Getting Spliterator object on vector v1
Spliterator<Integer> splitr1 = str.spliterator();
//Printing estimateSize of vector
System.out.println("Estimated size:" + splitr1.estimateSize());
System.out.println("Contents of vector:");
//Use forEachRemaining method
splitr1.forEachRemaining((n) -> System.out.println(n));
}
}
输出:
Estimated size:4 Contents of vector: 10 30 20 40
例子2
import java.util.*;
import java.util.stream.Stream;
public class VectorSpliteratorExample2 {
public static void main(String arg[]) {
Vector<String> vec = new Vector<>();
vec.addElement("One");
vec.addElement("Two");
vec.addElement("Three");
vec.addElement("Four");
vec.addElement("Five");
//Obtain a Stream to the vector
Stream<String> str = vec.stream();
//Getting Spliterator object on vector vec
Spliterator<String> splitr1 = str.spliterator();
//Printing estimateSize of vector
System.out.println("Estimated size:" + splitr1.estimateSize());
System.out.println("Contents of vector:");
//Use forEachRemaining method
splitr1.forEachRemaining((n) -> System.out.println(n));
}
}
输出:
Estimated size:5 Contents of vector: One Two Three Four Five
相关用法
- Java Vector set()用法及代码示例
- Java Vector subList()用法及代码示例
- Java Vector setSize()用法及代码示例
- Java Vector sort()用法及代码示例
- Java Vector setElementAt()用法及代码示例
- Java Vector size()用法及代码示例
- Java Vector removeIf()用法及代码示例
- Java Vector toArray()用法及代码示例
- Java Vector addAll()用法及代码示例
- Java Vector listIterator()用法及代码示例
- Java Vector addElement()用法及代码示例
- Java Vector removeRange()用法及代码示例
- Java Vector clone()用法及代码示例
- Java Vector ensureCapacity()用法及代码示例
- Java Vector trimToSize()用法及代码示例
- Java Vector replaceAll()用法及代码示例
- Java Vector iterator()用法及代码示例
- Java Vector firstElement()用法及代码示例
- Java Vector insertElementAt()用法及代码示例
- Java Vector toString()用法及代码示例
注:本文由纯净天空筛选整理自 Java Vector spliterator() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。