본문 바로가기
코틀린/[Extraction] 추출 작업

[Kotlin][Collection] subList

by jinwo_o 2024. 12. 2.

지정된 fromIndex(포함)와 toIndex(제외) 사이의 이 목록 부분에 대한 뷰를 반환합니다. 반환된 목록은 이 목록에 의해 백업되므로 반환된 목록의 비구조적 변경 사항은 이 목록에 반영되고 그 반대의 경우도 마찬가지입니다. 기본 목록의 구조적 변경 사항은 뷰의 동작을 정의되지 않게 만듭니다.

public actual fun subList(fromIndex: Int, toIndex: Int): List<E>


val numbers = mutableListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val subList = numbers.subList(2, 6)

println(numbers)  // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
println(subList)  // [3, 4, 5, 6]

subList[0] = 99
println(subList)  // [99, 4, 5, 6]
println(numbers)  // [1, 2, 99, 4, 5, 6, 7, 8, 9, 10]

 

subList

subList CommonJSJVMNativeWasm-JSWasm-WASI 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 non-structural changes in the returned list are reflected

kotlinlang.org

'코틀린 > [Extraction] 추출 작업' 카테고리의 다른 글

[Kotlin][String] indexOf  (0) 2024.09.10
[Kotlin][Array] copyOfRange  (0) 2024.09.06
[Kotlin][Array] sliceArray  (0) 2024.09.06