SHARE
TWEET

Untitled

myshkin1 Apr 19th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Collections;
  4. import java.util.List;
  5.  
  6. class Test {
  7.     public static void main(String[] args) {
  8.         List<Integer> data = Collections.synchronizedList(new ArrayList<>());
  9.         Arrays.asList(1,2,3,4,5,6).parallelStream()
  10.                 .map(i -> {data.add(i); return i;}) // AVOID STATEFUL LAMBDA EXPRESSIONS!
  11.                 .forEachOrdered(i -> System.out.print(i+" "));
  12.         System.out.println();
  13.         for(Integer e: data) {
  14.             System.out.print(e+" ");
  15.         }
  16.     }
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top