scala> Array(1, 2, 3).toString
res1: String = [I@11cf437c
scala> List(1, 2, 3).toString
res2: String = List(1, 2, 3)
scala> Vector(1, 2, 3).toString
res3: String = Vector(1, 2, 3)
Logically, one would expect Array(1, 2, 3).toString
to return "Array(1, 2, 3)"
.
Update: seems to me like Array
maps to the built in Java array type—is this correct? and if yes, is this the reason Array.toString
has to behave like this?
It is because Array
is a Java object. You can however use runtime.ScalaRunTime.stringOf
if it suits your needs.
scala> runtime.ScalaRunTime.stringOf(Array(1, 2, 3))
res3: String = Array(1, 2, 3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With