Xóa bài viết
Bạn có chắc chắn muốn xóa bài viết này không ?
Xóa bình luận
Bạn có chắc chắn muốn xóa bình luận này không ?
Kotlin Array find the Largest Element – max() maxBy() maxWith() methods
Kotlin Array find the Largest Element – max() maxBy() maxWith() methods
https://grokonez.com/kotlin/kotlin-array-find-largest-element-max-maxby-maxwith-methods
In the tutorial, JavaSampleApproach will show how to use Kotlin Array methods max()
, maxBy()
, maxWith()
to find the largest element in a Kotlin Array.
I. max() method
Kotlin Array method max()
is used to returns the largest element or null
if there are no elements. If any of elements is NaN
, it returns NaN
.
Method signatures:
//1.
public fun Array.max(): Double?
//2.
public fun Array.max(): Float?
Example:
package com.javasampleapproach.kotlin.array
fun main(args : Array){
val simpleArray = arrayOf(1.99, 55.4, 20.0, 99.99, 23.0, 34.2, 88.0, 72.1, 61.2, 43.9)
// public fun Array.max(): Double?
val largestElement = simpleArray.max()
println(largestElement)
// ->
/*
99.99
*/
}
max() with Comparable
More at:
https://grokonez.com/kotlin/kotlin-array-find-largest-element-max-maxby-maxwith-methods
Bình luận

{{ comment.user.name }}
Bỏ hay
Hay

Cùng một tác giả

1
0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...

1
0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...

1
0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
Bài viết liên quan

0
0

0
0
https://grokonez.com/kotlin/kotlinreadwritecsvfileexample How to read/write CSV file in Kotlin In this tutorial, we're gonna look at examples tha...