I am having problem with most basic Scala operation and it is making me crazy.
val a = Array(1,2,3) println(a) and result is [I@1e76345 println(a.toString()) and result is [I@1e76345 println(a.toString) and result is [I@1e76345
Can anyone tell me how to print array without writing my own function for doing that because that is silly. Thanks!
Array is a special kind of collection in scala. it is a fixed size data structure that stores elements of the same data type. The index of the first element of an array is zero and the last element is the total number of elements minus one. It is a collection of mutable values.
The mkString() method is utilized to display all the elements of the list in a string along with a separator. Method Definition: def mkString(sep: String): String. Return Type: It returns all the elements of the list in a string along with a separator. Example #1: // Scala program of mkString()
mkString
will convert collections (including Array
) element-by-element to string representations.
println(a.mkString(" "))
is probably what you want.
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