Close

Java 8 Streams - Stream.isParallel Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.BaseStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamLogicBig

Method:

boolean isParallel()

Returns whether this stream would execute in parallel during a terminal operation. This method should be called before calling a terminal operation.


Examples


package com.logicbig.example.stream;

import java.util.stream.Stream;

public class IsParallelExample {

public static void main(String... args) {
Stream<String> stream = Stream.of("one", "two", "three", "four");
stream = stream.parallel();
System.out.println(stream.isParallel());
}
}

Output

true




package com.logicbig.example.stream;

import java.util.stream.Stream;

public class IsParallelExample2 {

public static void main(String... args) {
Stream<String> stream = Stream.of("one", "two", "three", "four");
System.out.println(stream.isParallel());
}
}

Output

false




See Also