Array.toString vs List.toString

Hi,

Any reason why array doesn’t have a nice toString method, just like List?

fun main(args: Array<String>) {
    println(listOf(1,2,3))
    println(arrayOf(1,2,3))
}

output: 
[1, 2, 3]
[Ljava.lang.Integer;@36b29562

The implementation of both of these toString() methods is provided by the JVM; Kotlin has no influence on that.

1 Like

For arrays you can use contentToString() extension function which replicates List.toString functionality.

2 Likes

Can they be overridden in Kotlin std-lib?

No, they can’t.