how to declare string array in kotlin

Declaring a String Array in Kotlin

To declare a string array in Kotlin, follow these steps:

  1. Using the arrayOf() function:
  2. Use the arrayOf() function to create an array of strings.
  3. Example: kotlin val stringArray = arrayOf("apple", "banana", "orange")

  4. Using the Array constructor:

  5. Use the Array constructor to create an array of strings.
  6. Example: kotlin val stringArray = Array(3) { "" } stringArray[0] = "apple" stringArray[1] = "banana" stringArray[2] = "orange"

  7. Using the emptyArray() function:

  8. Use the emptyArray() function to create an empty array of strings.
  9. Example: kotlin val stringArray = emptyArray<String>()

  10. Using the constructor with an initializer:

  11. Use the constructor with an initializer to create an array of strings.
  12. Example: kotlin val stringArray = Array(3) { index -> "Element $index" }