get Or Else
inline fun <T> Array<out T>.getOrElse(index: Int, defaultValue: (Int) -> T): T
Content copied to clipboard
inline fun ByteArray.getOrElse(index: Int, defaultValue: (Int) -> Byte): Byte
Content copied to clipboard
inline fun ShortArray.getOrElse(index: Int, defaultValue: (Int) -> Short): Short
Content copied to clipboard
inline fun IntArray.getOrElse(index: Int, defaultValue: (Int) -> Int): Int
Content copied to clipboard
inline fun LongArray.getOrElse(index: Int, defaultValue: (Int) -> Long): Long
Content copied to clipboard
inline fun FloatArray.getOrElse(index: Int, defaultValue: (Int) -> Float): Float
Content copied to clipboard
inline fun DoubleArray.getOrElse(index: Int, defaultValue: (Int) -> Double): Double
Content copied to clipboard
inline fun BooleanArray.getOrElse(index: Int, defaultValue: (Int) -> Boolean): Boolean
Content copied to clipboard
inline fun CharArray.getOrElse(index: Int, defaultValue: (Int) -> Char): Char
Content copied to clipboard
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this array.
inline fun <T> List<T>.getOrElse(index: Int, defaultValue: (Int) -> T): T
Content copied to clipboard
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this list.
inline fun UIntArray.getOrElse(index: Int, defaultValue: (Int) -> UInt): UInt
Content copied to clipboard
inline fun ULongArray.getOrElse(index: Int, defaultValue: (Int) -> ULong): ULong
Content copied to clipboard
inline fun UByteArray.getOrElse(index: Int, defaultValue: (Int) -> UByte): UByte
Content copied to clipboard
inline fun UShortArray.getOrElse(index: Int, defaultValue: (Int) -> UShort): UShort
Content copied to clipboard
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this array.
Since Kotlin
1.3
Returns the value for the given key, or the result of the defaultValue function if there was no entry for the given key.
Samples
import samples.*
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
val map = mutableMapOf<String, Int?>()
assertPrints(map.getOrElse("x") { 1 }, "1")
map["x"] = 3
assertPrints(map.getOrElse("x") { 1 }, "3")
map["x"] = null
assertPrints(map.getOrElse("x") { 1 }, "1")
//sampleEnd
}