title: Parallel stream from a HashSet doesn't run in parallel
body: <p>I have collection of elements that I want to process in parallel. When I use a <code>List</code>, parallelism works. However, when I use a <code>Set</code>, it does not run in parallel.</p>
  
  <p>I wrote a code sample that shows the problem:</p>
  
  <pre><code>public static void main(String[] args) {
      ParallelTest test = new ParallelTest();
  
      List&lt;Integer&gt; list = Arrays.asList(1,2);
      Set&lt;Integer&gt; set = new HashSet&lt;&gt;(list);
  
      ForkJoinPool forkJoinPool = new ForkJoinPool(4);
  
      System.out.println("set print");
      try {
          forkJoinPool.submit(() -&gt;
              set.parallelStream().forEach(test::print)
          ).get();
      } catch (Exception e) {
          return;
      }
  
      System.out.println("\n\nlist print");
      try {
          forkJoinPool.submit(() -&gt;
              list.parallelStream().forEach(test::print)
          ).get();
      } catch (Exception e) {
          return;
      }   
  }
  
  private void print(int i){
      System.out.println("start: " + i);
      try {
          TimeUnit.SECONDS.sleep(1);
      } catch (InterruptedException e) {
      }
      System.out.println("end: " + i);
  }
  </code></pre>
  
  <p>This is the output that I get on windows 7</p>
  
  <pre><code>set print
  start: 1
  end: 1
  start: 2
  end: 2
  
  list print
  start: 2
  start: 1
  end: 1
  end: 2
  </code></pre>
  
  <p>We can see that the first element from the <code>Set</code> had to finish before the second element is processed. For the <code>List</code>, the second element starts before the first element finishes.</p>
  
  <p>Can you tell me what causes this issue, and how to avoid it using a <code>Set</code> collection? </p>