You can also use Array<Array<String>>. Note that the compiler can automatically infer this type, but specifying the type may help you understand better what's going on. Here is an example with output:
fun main() {
// Create the 2D array of Strings
val string2DArray: Array<Array<String>> = arrayOf(
arrayOf("apple", "orange", "avocado", "mango", "banana"),
arrayOf("_", "!", ":", "?"),
arrayOf("1", "2", "3", "4", "5", "10"))
// Print the 2D array
string2DArray.forEach {
it.forEach { it -> print("$it, ") }
println()
}
// Access an individual String using index notation.
println("My favorite fruit is: ${string2DArray[0][2]}")
}
Output:
apple, orange, avocado, mango, banana,
_, !, :, ?,
1, 2, 3, 4, 5, 10,
My favorite fruit is: avocado