Kotlin collection methods – groupBy(), sumByDouble(), mapValues(), toSortedMap() example

In the tutorial, JavaSampleApproach will show you how to combine Kotlin collection methods: groupBy(), sumByDouble() with Kotlin List and mapValues(), toSortedMap() with Kotlin Map.

1. Kotlin collection methods – groupBy(), sumByDouble(), mapValues(), toSortedMap()

groupBy() with method signature:

-> groupBy() is used to group elements of the given collection by the key returned by the given [keySelector] function. Result is a map collection.

Practice:

mapValues() with method signature:

-> mapValues() is used to create a new map that uses [transform] function to produce the new values.

And sumByDouble() with method signature:

-> sumByDouble() returns the sum of all values produced by [selector] function applied to each element in the collection..

Practice:

toSortedMap() with method signature:

-> toSortedMap() converts this [Map] to a [SortedMap]

Practice:

2. Full Sourcecode

By JavaSampleApproach | January 9, 2018.


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*