copyOf

external fun <T> Array<T>.copyOf(): Array<T>(source)

Returns a new array containing the same elements.

The copy has the same length and element type but its own mutable storage. Referenced objects are shared, not cloned.

Receiver

the array to copy.

Return

a distinct array containing these elements in order.

Type Parameters

T

the element type.


external fun <T> Array<T>.copyOf(newSize: Int): Array<T?>(source)

Returns a resized copy, padding extra elements with null.

Copies the first minOf(size, newSize) elements. A smaller size discards the tail; a larger size adds null elements. The result has a nullable element type even when shrinking. The source is unchanged. Referenced objects are shared, not cloned.

Receiver

the array to copy.

Return

a new array of newSize elements.

Parameters

newSize

the length of the result.

Type Parameters

T

the source element type.

Throws


external fun ByteArray.copyOf(): ByteArray(source)
external fun CharArray.copyOf(): CharArray(source)
external fun IntArray.copyOf(): IntArray(source)
external fun LongArray.copyOf(): LongArray(source)
external fun UIntArray.copyOf(): UIntArray(source)

Returns a new array containing the same elements.

The copy has the same length and element type but its own mutable storage.

Receiver

the array to copy.

Return

a distinct array containing these elements in order.


external fun BooleanArray.copyOf(newSize: Int): BooleanArray(source)

Returns a resized copy, padding extra elements with false.

Copies the first minOf(size, newSize) elements. A smaller size discards the tail; a larger size adds false elements. The source is unchanged.

Receiver

the array to copy.

Return

a new array of newSize elements.

Parameters

newSize

the length of the result.

Throws


external fun ByteArray.copyOf(newSize: Int): ByteArray(source)
external fun ShortArray.copyOf(newSize: Int): ShortArray(source)
external fun IntArray.copyOf(newSize: Int): IntArray(source)
external fun LongArray.copyOf(newSize: Int): LongArray(source)
external fun FloatArray.copyOf(newSize: Int): FloatArray(source)
external fun DoubleArray.copyOf(newSize: Int): DoubleArray(source)
external fun UByteArray.copyOf(newSize: Int): UByteArray(source)
external fun UShortArray.copyOf(newSize: Int): UShortArray(source)
external fun UIntArray.copyOf(newSize: Int): UIntArray(source)
external fun ULongArray.copyOf(newSize: Int): ULongArray(source)

Returns a resized copy, padding extra elements with zero.

Copies the first minOf(size, newSize) elements. A smaller size discards the tail; a larger size adds zero-valued elements. The source is unchanged.

Receiver

the array to copy.

Return

a new array of newSize elements.

Parameters

newSize

the length of the result.

Throws


external fun CharArray.copyOf(newSize: Int): CharArray(source)

Returns a resized copy, padding extra elements with zero characters.

Copies the first minOf(size, newSize) elements. A smaller size discards the tail; a larger size adds '\u0000' characters. The source is unchanged.

Receiver

the array to copy.

Return

a new array of newSize elements.

Parameters

newSize

the length of the result.

Throws