How to declare an array of strings in Kotlin? Equivalent of Java String[]
I just started learning Kotlin after Java, and I ran into a simple but confusing problem.
In Java I'm used to writing:
```java
String[] names = new String[]{"Alice", "Bob", "Charlie"};
```
But in Kotlin I see several options and don't understand which one is correct.
I tried:
```kotlin
val names = arrayOf("Alice", "Bob", "Charlie")
```
But this returns `Array`, not `String[]`. Is there a difference? Or do I need to use `Array` everywhere?
I also came across `listOf("Alice", "Bob", "Charlie")`, which returns `List`. But I need an array specifically because I'm passing it to a Java method that expects `String[]`.
Please tell me what syntax in Kotlin corresponds to Java `String[]`? And how to correctly create an array of strings if I
No answers yet.
Log in to leave an answer
Blogs