parallelStream(): This method is available in java.util.LinkedHashSet class of Java.
Syntax:
Stream<K> java.util.Collection.parallelStream()
This method returns a possibly parallel Stream with this collection as its source. It is allowable for this method to return a sequential stream.
Parameters: NA
Returns: a possibly parallel Stream over the elements in this collection.
Exceptions: NA
Approach
Java
import java.util.LinkedHashSet;import java.util.stream.Stream;public class LinkedHashSetparallelStream {public static void main(String[] args) {LinkedHashSet<String> linkedHashSet =new LinkedHashSet<>();linkedHashSet.add("Hello");linkedHashSet.add("Java");Stream<String> stream = linkedHashSet.parallelStream();System.out.println(stream.count());}}
Output:
2
No comments:
Post a Comment