import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.function.Function;
import java.util.stream.Collectors;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) {
        List<Integer> values = List.of(1, 4, 2, 62, 2, 9);

        Function<Integer, String> classifier = valor -> valor % 2 == 0 ? "par" : "inpar";

        Map<String, List<Integer>> grupos = values.stream().collect(Collectors.groupingBy(classifier));

        grupos.forEach((key, value) -> System.out.println(key + ": " + value));
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: