copyOf
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("foo", "bar", "baz")
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [foo, bar]
val paddedCopy = array.copyOf(5) { "qux" }
println(paddedCopy.contentToString()) // [foo, bar, baz, qux, qux]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = byteArrayOf(1, 2, 3)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1, 2]
val paddedCopy = array.copyOf(5) { -1 }
println(paddedCopy.contentToString()) // [1, 2, 3, -1, -1]
val paddedCopyWithIndex = array.copyOf(6) { it.toByte() }
println(paddedCopyWithIndex.contentToString()) // [1, 2, 3, 3, 4, 5]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = shortArrayOf(1, 2, 3)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1, 2]
val paddedCopy = array.copyOf(5) { -1 }
println(paddedCopy.contentToString()) // [1, 2, 3, -1, -1]
val paddedCopyWithIndex = array.copyOf(6) { it.toShort() }
println(paddedCopyWithIndex.contentToString()) // [1, 2, 3, 3, 4, 5]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1, 2]
val paddedCopy = array.copyOf(5) { -1 }
println(paddedCopy.contentToString()) // [1, 2, 3, -1, -1]
val paddedCopyWithIndex = array.copyOf(6) { it }
println(paddedCopyWithIndex.contentToString()) // [1, 2, 3, 3, 4, 5]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = longArrayOf(1, 2, 3)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1, 2]
val paddedCopy = array.copyOf(5) { -1 }
println(paddedCopy.contentToString()) // [1, 2, 3, -1, -1]
val paddedCopyWithIndex = array.copyOf(6) { it.toLong() }
println(paddedCopyWithIndex.contentToString()) // [1, 2, 3, 3, 4, 5]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = floatArrayOf(1.0f, 2.0f, 3.0f)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1.0, 2.0]
val paddedCopy = array.copyOf(5) { -1.0f }
println(paddedCopy.contentToString()) // [1.0, 2.0, 3.0, -1.0, -1.0]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = doubleArrayOf(1.0, 2.0, 3.0)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1.0, 2.0]
val paddedCopy = array.copyOf(5) { -1.0 }
println(paddedCopy.contentToString()) // [1.0, 2.0, 3.0, -1.0, -1.0]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = booleanArrayOf(true, false, true)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [true, false]
val paddedCopy = array.copyOf(5) { it % 2 == 0 }
println(paddedCopy.contentToString()) // [true, false, true, false, true]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = charArrayOf('a', 'b', 'c')
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [a, b]
val paddedCopy = array.copyOf(5) { '?' }
println(paddedCopy.contentToString()) // [a, b, c, ?, ?]
//sampleEnd
}
Returns new array which is a copy of the original array.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopy = array.copyOf()
println(arrayCopy.contentToString()) // [apples, oranges, limes]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with zero values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with zero values.
Since Kotlin
1.3Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = uintArrayOf(1u, 2u, 3u)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1, 2]
val paddedCopy = array.copyOf(5) { 0xffu }
println(paddedCopy.contentToString()) // [1, 2, 3, 255, 255]
val paddedCopyWithIndex = array.copyOf(6) { it.toUInt() }
println(paddedCopyWithIndex.contentToString()) // [1, 2, 3, 3, 4, 5]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = ulongArrayOf(1u, 2u, 3u)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1, 2]
val paddedCopy = array.copyOf(5) { 0xffu }
println(paddedCopy.contentToString()) // [1, 2, 3, 255, 255]
val paddedCopyWithIndex = array.copyOf(6) { it.toULong() }
println(paddedCopyWithIndex.contentToString()) // [1, 2, 3, 3, 4, 5]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = ubyteArrayOf(1u, 2u, 3u)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1, 2]
val paddedCopy = array.copyOf(5) { 0xffu }
println(paddedCopy.contentToString()) // [1, 2, 3, 255, 255]
val paddedCopyWithIndex = array.copyOf(6) { it.toUByte() }
println(paddedCopyWithIndex.contentToString()) // [1, 2, 3, 3, 4, 5]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with values calculated by calling the specified init function.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with values calculated by calling the specified init function.
The function init is called sequentially for each array element in range starting from the index corresponding to the source array size until newSize. It should return the value for an array element given its index.
Since Kotlin
2.2Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = ushortArrayOf(1u, 2u, 3u)
val truncatedCopy = array.copyOf(2)
println(truncatedCopy.contentToString()) // [1, 2]
val paddedCopy = array.copyOf(5) { 0xffu }
println(paddedCopy.contentToString()) // [1, 2, 3, 255, 255]
val paddedCopyWithIndex = array.copyOf(6) { it.toUShort() }
println(paddedCopyWithIndex.contentToString()) // [1, 2, 3, 3, 4, 5]
//sampleEnd
}
Returns new array which is a copy of the original array.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopy = array.copyOf()
println(arrayCopy.contentToString()) // [apples, oranges, limes]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
null
values.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [apples, oranges, limes, null, null]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [apples, oranges]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with zero values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with zero values.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with false
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
false
values.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null char (\u0000
) values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with null char (
\u0000
) values.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopy = array.copyOf()
println(arrayCopy.contentToString()) // [apples, oranges, limes]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
null
values.
Since Kotlin
1.1Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with zero values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with zero values.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with false
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
false
values.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null char (\u0000
) values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with null char (
\u0000
) values.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopy = array.copyOf()
println(arrayCopy.contentToString()) // [apples, oranges, limes]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
null
values.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [apples, oranges, limes, null, null]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [apples, oranges]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with zero values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with zero values.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with false
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
false
values.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null char (\u0000
) values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with null char (
\u0000
) values.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopy = array.copyOf()
println(arrayCopy.contentToString()) // [apples, oranges, limes]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
null
values.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [apples, oranges, limes, null, null]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [apples, oranges]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with zero values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with zero values.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with false
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
false
values.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null char (\u0000
) values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with null char (
\u0000
) values.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopy = array.copyOf()
println(arrayCopy.contentToString()) // [apples, oranges, limes]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
null
values.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [apples, oranges, limes, null, null]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [apples, oranges]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with zero values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with zero values.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with false
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
false
values.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null char (\u0000
) values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with null char (
\u0000
) values.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopy = array.copyOf()
println(arrayCopy.contentToString()) // [apples, oranges, limes]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
null
values.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = arrayOf("apples", "oranges", "limes")
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [apples, oranges, limes, null, null]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [apples, oranges]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with zero values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with zero values.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with false
values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with
false
values.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}
Returns new array which is a copy of the original array, resized to the given newSize. The copy is either truncated or padded at the end with null char (\u0000
) values if necessary.
If newSize is less than the size of the original array, the copy array is truncated to the newSize.
If newSize is greater than the size of the original array, the extra elements in the copy array are filled with null char (
\u0000
) values.
Since Kotlin
1.8Samples
import kotlin.test.*
fun main() {
//sampleStart
val array = intArrayOf(1, 2, 3)
val arrayCopyPadded = array.copyOf(5)
println(arrayCopyPadded.contentToString()) // [1, 2, 3, 0, 0]
val arrayCopyTruncated = array.copyOf(2)
println(arrayCopyTruncated.contentToString()) // [1, 2]
//sampleEnd
}