What's the Kotlin equivalent of Java's String[]?

后端 未结 8 1196
感情败类
感情败类 2020-12-23 08:26

I see that Kotlin has ByteArray, ShortArray, IntArray, CharArray, DoubleArray, FloatArray, which are equivalent to byte[], short[], int[],char[], double[]

相关标签:
8条回答
  • 2020-12-23 09:27

    use arrayOf, arrayOfNulls, emptyArray

    var colors_1: Array<String> = arrayOf("green", "red", "blue")
    var colors_2: Array<String?> = arrayOfNulls(3)
    var colors_3: Array<String> = emptyArray()
    
    0 讨论(0)
  • 2020-12-23 09:28

    Those types are there so that you can create arrays of the primitives, and not the boxed types. Since String isn't a primitive in Java, you can just use Array<String> in Kotlin as the equivalent of a Java String[].

    0 讨论(0)
提交回复
热议问题