All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin.collections.ArraysJVM.kt Maven / Gradle / Ivy

There is a newer version: 01.02.00-RPM
Show newest version
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("ArraysKt")

package kotlin.collections

import java.nio.charset.Charset


/**
 * Converts the contents of this byte array to a string using the specified [charset].
 */
@kotlin.internal.InlineOnly
public inline fun ByteArray.toString(charset: Charset): String = String(this, charset)

/**
 * Returns a *typed* array containing all of the elements of this collection.
 *
 * Allocates an array of runtime type `T` having its size equal to the size of this collection
 * and populates the array with the elements of this collection.
 */
public inline fun  Collection.toTypedArray(): Array {
    val thisCollection = this as java.util.Collection
    return thisCollection.toArray(arrayOfNulls(thisCollection.size())) as Array
}

/** Returns the array if it's not `null`, or an empty array otherwise. */
public inline fun  Array?.orEmpty(): Array = this ?: arrayOf()

/** Internal unsafe construction of array based on reference array type */
internal fun  arrayOfNulls(reference: Array, size: Int): Array {
    return java.lang.reflect.Array.newInstance(reference.javaClass.componentType, size) as Array
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy