takeLastWhile

The takeLastWhile function also accepts a lambda expression. This function takes elements from the end of a list until the condition is not satisfied:

newList = numbers.takeLastWhile { it > 5 }
println("Take all elements from end of the list, which are greater than 5")
println(newList)

Here, the output is [8, 9, 10]. The takeLastWhile function starts executing from the end of the list and stops executing when the given condition becomes false.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.166.255