/* package whatever; // don't place package name! */

import java.util.*;
import java.util.stream.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		double sFF = 0;
		double cAT = 0;
		
		for (int i = 0; i <= 100; ++i) {
		List<Integer> list = new Random(0).ints().limit(5).boxed().collect(Collectors.toList());
		long start = System.nanoTime();
		list.stream().collect(Collectors.collectingAndThen(
			Collectors.maxBy(Comparator.naturalOrder()),
			(Optional<Integer> n) -> n.orElse(0)));
		long end = System.nanoTime();
		cAT = (end - start) / 1e6;
		
		start = System.nanoTime();
		list.stream().sorted().findFirst().get();
		end = System.nanoTime();
		sFF = (end - start) / 1e6;
		
		if (i == 0 || i == 100) {
			System.out.println("Iteration " + i);
		System.out.println("collectAndThen " + cAT);
		System.out.println("sortFindFirst " + sFF);
		}
		}
	}
}