subList
Returns a view of the portion of this list between the specified fromIndex (inclusive) and toIndex (exclusive). The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice versa.
Structural changes in the base list make the behavior of the view unspecified.
Since Kotlin
1.0Throws
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf(1, 2, 3, 4, 5)
println(list.subList(2, 4)) // [3, 4]
val mutableList = mutableListOf(1, 2, 3, 4, 5)
val subList = mutableList.subList(2, 4)
println(subList) // [3, 4]
mutableList[3] = -1
println(subList) // [3, -1]
// list.subList(0, 100) // will fail with IndexOutOfBoundsException
//sampleEnd
}
Returns a view of the portion of this list between the specified fromIndex (inclusive) and toIndex (exclusive). The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa.
Structural changes in the base list make the behavior of the view unspecified.
Since Kotlin
1.3Throws
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf(1, 2, 3, 4, 5)
println(list.subList(2, 4)) // [3, 4]
val mutableList = mutableListOf(1, 2, 3, 4, 5)
val subList = mutableList.subList(2, 4)
println(subList) // [3, 4]
mutableList[3] = -1
println(subList) // [3, -1]
// list.subList(0, 100) // will fail with IndexOutOfBoundsException
//sampleEnd
}
Returns a view of the portion of this list between the specified fromIndex (inclusive) and toIndex (exclusive). The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa.
Structural changes in the base list make the behavior of the view unspecified.
Since Kotlin
1.8Throws
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf(1, 2, 3, 4, 5)
println(list.subList(2, 4)) // [3, 4]
val mutableList = mutableListOf(1, 2, 3, 4, 5)
val subList = mutableList.subList(2, 4)
println(subList) // [3, 4]
mutableList[3] = -1
println(subList) // [3, -1]
// list.subList(0, 100) // will fail with IndexOutOfBoundsException
//sampleEnd
}
Returns a view of the portion of this list between the specified fromIndex (inclusive) and toIndex (exclusive). The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa.
Structural changes in the base list make the behavior of the view unspecified.
Since Kotlin
1.8Throws
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf(1, 2, 3, 4, 5)
println(list.subList(2, 4)) // [3, 4]
val mutableList = mutableListOf(1, 2, 3, 4, 5)
val subList = mutableList.subList(2, 4)
println(subList) // [3, 4]
mutableList[3] = -1
println(subList) // [3, -1]
// list.subList(0, 100) // will fail with IndexOutOfBoundsException
//sampleEnd
}