Limit function in Kotlin

Java 8 has a limit thread method:

 package com.concretepage.util.stream; import java.util.Arrays; import java.util.List; public class LimitDemo { public static void main(String[] args) { List<String> list = Arrays.asList("AA","BB","CC","DD","EE"); list.stream().limit(3).forEach(s->System.out.println(s)); } } 

exit:

 AA BB CC 

What is the name of the analogue in Kotlin, or how to do it better in another way?

+7
java-8 java-stream kotlin
source share
1 answer

Based on the documentation :

 list.take(3).forEach(::System.out.println) 
+16
source share

All Articles