truncateTo

fun <T> MutableList<T>.truncateTo(size: Int)

Truncates the mutable list to the specified size by removing all elements beyond the target size. If the current size is already less than or equal to the specified size, the list remains unchanged.

Parameters

size

the target size to truncate the list to. Must be non-negative and not greater than the current list size.