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

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/* 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
	{
		//My silly test predicate
		Predicate<String> p = s -> s.length() > 4;

		//List with test strings (even though it's called numbers...)
        List<String> numbers = new ArrayList<>(List.of("Ted", "James", "Bobby", "Mark", "Hank", "Richard"));

		//Partitioning by your first example
        Map<Boolean, List<String>> partitioned = numbers.stream()
                .collect(Collectors.partitioningBy(p));

		//Printing the result
        System.out.println(partitioned);

		//Partitioning with int keys
        Map<Integer, List<String>> partitioned2 = numbers.stream()
                .collect(Collectors.toMap(s -> p.test(s) ? 1 : 0, s -> new ArrayList<>(List.of(s)), (list1, list2) -> {
                    list1.addAll(list2);
                    return list1;
                }));

		//Printing the second partition to compare it with the first one
        System.out.println(partitioned2);
	}
}