![]() ![]() ![]() ![]() listOfNotNull: Returns a new read-only list either of single given element, if it is not null, or empty list if the element is null.listOf: Returns an immutable list containing only the specified object element.Per the Kotlin docs, the difference between listOf and listOfNotNull: ![]() Use these functions to create lists in Kotlin: Function If you look at the IntArray source code you’ll see that it doesn’t extend Array. It’s also important to note that IntArray is not an Array, which you can get a hint of when I explicitly show the return types for some of these functions: Notice not only the function names, but their return types as well. Other Kotlin arrays that you can create are shown in the source code:įun doubleArrayOf(vararg elements: Double): DoubleArrayįun floatArrayOf(vararg elements: Float): FloatArrayįun longArrayOf(vararg elements: Long): LongArrayįun intArrayOf(vararg elements: Int): IntArrayįun charArrayOf(vararg elements: Char): CharArrayįun shortArrayOf(vararg elements: Short): ShortArrayįun byteArrayOf(vararg elements: Byte): ByteArrayįun booleanArrayOf(vararg elements: Boolean): BooleanArray Val x = IntArrayOf(1,2,3) // Kotlin.IntArray I need to dig into this more but I know there are these Kotlin array-creation functions: With Kotlin you can create lists, maps, and sets with standard functions that are automatically in scope. ![]()
0 Comments
Leave a Reply. |