DoubleStream parallel()是java.util.stream.DoubleStream中的方法。此方法返回一個並行DoubleStream,即,它可能會返回自身,這是因為該流已經存在,或者是因為基礎流狀態已被修改為並行。
DoubleStream parallel()是中間操作。這些操作總是很懶。在Stream實例上調用中間操作,並在完成處理後將中間實例作為輸出提供。
用法:
DoubleStream parallel() Where, DoubleStream is a sequence of primitive double-valued elements and the function returns a parallel DoubleStream.
示例1:
// Java program to demonstrate working of
// DoubleStream parallel() on a given range
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating a stream of doubles
DoubleStream stream =
DoubleStream.of(5.2, 12.6, 4.5, 7.8);
System.out.println("The corresponding "
+ "parallel DoubleStream is :");
stream.parallel().forEach(System.out::println);
}
}
輸出:
The corresponding parallel DoubleStream is : 4.5 7.8 12.6 5.2
示例2:
// Printing sequential stream for the
// same input as above example 1.
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating a stream of doubles
DoubleStream stream =
DoubleStream.of(5.2, 12.6, 4.5, 7.8);
System.out.println("The corresponding "
+ "sequential DoubleStream is :");
stream.sequential().forEach(System.out::println);
}
}
輸出:
The corresponding sequential DoubleStream is : 5.2 12.6 4.5 7.8
示例3:
// Java program to show sorted output
// of parallel stream.
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating a stream of doubles
DoubleStream stream =
DoubleStream.of(2.3, 3.0, 4.5, 6.6);
System.out.println("The sorted parallel"
+ " DoubleStream is :");
stream.parallel().sorted().forEach(System.out::println);
}
}
輸出:
The sorted parallel DoubleStream is : 4.5 6.6 2.3 3.0
相關用法
- Java DoubleStream sum()用法及代碼示例
- Java DoubleStream of()用法及代碼示例
- Java DoubleStream summaryStatistics()用法及代碼示例
- Java DoubleStream min()用法及代碼示例
- Java DoubleStream iterator()用法及代碼示例
- Java DoubleStream sequential()用法及代碼示例
- Java DoubleStream mapToInt()用法及代碼示例
- Java DoubleStream max()用法及代碼示例
- Java DoubleStream concat()用法及代碼示例
- Java DoubleStream sorted()用法及代碼示例
- Java DoubleStream toArray()用法及代碼示例
- Java DoubleStream mapToObj()用法及代碼示例
- Java DoubleStream mapToLong()用法及代碼示例
- Java DoubleStream skip()用法及代碼示例
- Java DoubleStream builder()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 DoubleStream parallel() in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。