In Kotlin we have count function which exactly provides the same output what we get in the length function. here we have an overloading function too which takes predicate lambda (Char -> Boolean) as an input param.
Lets see the below example and hope you will understand. Here we are about to find the No. of times the character occurs in the string, will see the code snippet in both Kotlin and Java versions.
Kotlin: Type Inference and lambda expression.
Java (Version< 8): In an optimized way, here we have written an extended logic by using recursive method and avoids the loops.
Java 8: Here the Lambda expression and filter function takes lambda expression and returns the IntStream and from that we can call IntStream functions, here data type has to be explicit and those not type inferences.