package com.winterbe.java8;

import java.util.Arrays;
import java.util.List;

/**
 * @author Benjamin Winterberg
 */
public class Streams12 {

    public static void main(String[] args) {
        List<String> strings = Arrays.asList("a1", "a2", "b1", "c2", "c1");

//        test1(strings);
//        test2(strings);
        test3(strings);
    }

    private static void test3(List<String> strings) {
        strings
            .parallelStream()
            .filter(s -> {
                System.out.format("filter:  %s [%s]\n", s, Thread.currentThread().getName());
                return true;
            })
            .map(s -> {
                System.out.format("map:     %s [%s]\n", s, Thread.currentThread().getName());
                return s.toUpperCase();
            })
            .sorted((s1, s2) -> {
                System.out.format("sort:    %s <> %s [%s]\n", s1, s2, Thread.currentThread().getName());
                return s1.compareTo(s2);
            })
            .forEach(s -> System.out.format("forEach: %s [%s]\n", s, Thread.currentThread().getName()));
    }

    private static void test2(List<String> strings) {
        strings
            .parallelStream()
            .filter(s -> {
                System.out.format("filter:  %s [%s]\n", s, Thread.currentThread().getName());
                return true;
            })
            .map(s -> {
                System.out.format("map:     %s [%s]\n", s, Thread.currentThread().getName());
                return s.toUpperCase();
            })
            .forEach(s -> System.out.format("forEach: %s [%s]\n", s, Thread.currentThread().getName()));
    }

    private static void test1() {
        // -Djava.util.concurrent.ForkJoinPool.common.parallelism=5

//        ForkJoinPool commonPool = ForkJoinPool.commonPool();
//        System.out.println(commonPool.getParallelism());
    }
}

@@ -48,31 +48,162 @@
 rray
-s;%0Aimport java.util.Lis
+List;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.UUID;%0Aimport java.util.concurrent.ForkJoinPool;%0Aimport java.util.concurrent.TimeUni
 t;%0A%0A
@@ -405,23 +405,16 @@
   test1(
-strings
 );%0A//   
@@ -454,24 +454,823 @@
 3(strings);%0A
+//        test4();%0A    %7D%0A%0A    private static void test4() %7B%0A        List%3CString%3E values = new ArrayList%3C%3E(100);%0A        for (int i = 0; i %3C 100; i++) %7B%0A            UUID uuid = UUID.randomUUID();%0A            values.add(uuid.toString());%0A        %7D%0A%0A        // sequential%0A%0A        long t0 = System.nanoTime();%0A%0A        long count = values%0A            .parallelStream()%0A            .sorted((s1, s2) -%3E %7B%0A                System.out.format(%22sort:    %25s %3C%3E %25s %5B%25s%5D%5Cn%22, s1, s2, Thread.currentThread().getName());%0A                return s1.compareTo(s2);%0A            %7D)%0A            .count();%0A        System.out.println(count);%0A%0A        long t1 = System.nanoTime();%0A%0A        long millis = TimeUnit.NANOSECONDS.toMillis(t1 - t0);%0A        System.out.println(String.format(%22parallel sort took: %25d ms%22, millis));%0A
     %7D%0A%0A    p
@@ -2662,18 +2662,16 @@
 lism=5%0A%0A
-//
         
@@ -2719,26 +2719,24 @@
 mmonPool();%0A
-//
         Syst

Add samples