Java Program to Print Hashset Elements Using ParallelStream() Method

Java program to print HashSet elements using parallelStream() method

// Java program to get a parallel stream 
// of a HashSet

import java.util.*;

class Main {
  public static void main(String[] args) {
    HashSet < Integer > nums = new HashSet();

    nums.add(1);
    nums.add(2);
    nums.add(3);
    nums.add(4);
    nums.add(5);
    nums.add(6);

    System.out.println("Set elements: ");
    nums.parallelStream().forEach(System.out::println);
  }
}

Output

Set elements: 
4
5
6
1
2
3
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment