getOrElse
inline
fun
<
T
>
Array
<
out
T
>
.
getOrElse
(
index
:
Int
,
defaultValue
:
(
Int
)
->
T
)
:
T
(source)
inline
fun
ShortArray
.
getOrElse
(
index
:
Int
,
defaultValue
:
(
Int
)
->
Short
)
:
Short
(source)
inline
fun
FloatArray
.
getOrElse
(
index
:
Int
,
defaultValue
:
(
Int
)
->
Float
)
:
Float
(source)
inline
fun
DoubleArray
.
getOrElse
(
index
:
Int
,
defaultValue
:
(
Int
)
->
Double
)
:
Double
(source)
inline
fun
BooleanArray
.
getOrElse
(
index
:
Int
,
defaultValue
:
(
Int
)
->
Boolean
)
:
Boolean
(source)
@ExperimentalUnsignedTypes
inline
fun
ULongArray
.
getOrElse
(
index
:
Int
,
defaultValue
:
(
Int
)
->
ULong
)
:
ULong
(source)
@ExperimentalUnsignedTypes
inline
fun
UByteArray
.
getOrElse
(
index
:
Int
,
defaultValue
:
(
Int
)
->
UByte
)
:
UByte
(source)
@ExperimentalUnsignedTypes
inline
fun
UShortArray
.
getOrElse
(
index
:
Int
,
defaultValue
:
(
Int
)
->
UShort
)
:
UShort
(source)
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.
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.
Returns the value for the given
key
if the value is present and not
null
.
Otherwise, returns the result of the
defaultValue
function.
import kotlin.test.*
import java.util.*
fun main(args: Array<String>) {
//sampleStart
val map = mutableMapOf<String, Int?>()
println(map.getOrElse("x") { 1 }) // 1
map["x"] = 3
println(map.getOrElse("x") { 1 }) // 3
map["x"] = null
println(map.getOrElse("x") { 1 }) // 1
//sampleEnd
}