Kotlin List methods – max() maxBy() maxWith() example

kotlin-list-methods-max-maxby-maxwith-feature-image

In the tutorial, JavaSampleApproach will show how to use Kotlin List methods max(), maxBy(), maxWith().

I. Kotlin List methods – max() maxBy() maxWith()

1. max()

max() is used to return the largest element of an Iterable. It will return ‘null’ if there are no element.
Method signature:

Practice:

2. maxBy()

maxBy() returns the first element having largest value of the given function selector: (T) -> R or ‘null’ if there are no elements.
Method signature:

Practice:

3. maxWith()

maxWith() returns the first element having the largest value according to the provided [comparator]
Method signature:

Practice:

II. Full Sourcecode



By grokonez | January 10, 2018.

Last updated on September 6, 2018.



Related Posts


Got Something To Say:

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

*