getLast

inline fun <T> Iterable<T>.getLast(defaultValue: T? = null): T(source)

Returns the last element of this or defaultValue if the iterable is empty. If this is a List with RandomAccess support, then this operation is guaranteed to be O(1).

Stream equivalent: Streams.findLast(stream).get()

Return

the last element of this or the default value

See also

Parameters

defaultValue

the value to return if this is empty

Throws

if the iterable is empty and the default value is null


inline fun <T> Iterator<T>.getLast(defaultValue: T? = null): T(source)

Advances this to the end, returning the last element or defaultValue if the iterator is empty and defaultValue is not null.

Return

the last element of this

See also

Throws

if the iterator is empty and defaultValue is null.