Avatar ·

What are the analogs of Java 8 Stream.collect in the Kotlin standard library?

Hello! I'm transitioning from Java to Kotlin and actively studying the standard library. In Java, I often used the Stream API, especially the collect method with various collectors: Collectors.toList(), Collectors.groupingBy(), Collectors.joining(), etc.

\n\n

For example, in Java I could write:

\n\n
List<String> names = people.stream()\n    .filter(p -> p.getAge() > 18)\n    .map(Person::getName)\n    .collect(Collectors.toList());\n
\n\n

Or group people by age:

\n\n
Map<Integer, List<Person>> byAge = people.stream()\n    .collect(Collectors.groupingBy(Person::getAge));\n
\n\n

In Kotlin, I see that there are functions .filter, .map, but I can't find