+ 6

Kotlin- When minOrNull() returns null?

var arr= arrayOf(1,2,3) print(arr.minOrNull()) The output is 1. When will the minOrNull() extension return null?šŸ¤”

21st May 2021, 8:36 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
2 Answers
+ 3
minOrNull() returns null when collection/array is empty https://kotlinlang.org/docs/collection-aggregate.html ""' minOrNull()Ā andĀ maxOrNull()Ā return the smallest and the largest element respectively. On empty collections, they returnĀ null. ""'
21st May 2021, 8:41 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
22nd May 2021, 6:42 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar