원래 배열의 지정된 범위의 복사본인 새 배열을 반환합니다.
public actual inline fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T> {
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
copyOfRangeImpl(fromIndex, toIndex)
} else {
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
}
}
val arr = arrayOf(1, 2, 3, 4, 5)
print(arr.copyOfRange(2, 4).joinToString()) // 3, 4
'코틀린 > [Extraction] 추출 작업' 카테고리의 다른 글
[Kotlin][String] indexOf (0) | 2024.09.10 |
---|---|
[Kotlin][Array] sliceArray (0) | 2024.09.06 |
[Kotlin][Char] code (0) | 2024.09.03 |