Array.toString vs List.toString


#1

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

#2

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


#3

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


#4

Can they be overridden in Kotlin std-lib?


#5

No, they can’t.