I'm having a problem with two dimensional array. I want the array to be like a table and not say Array (), Array().
Something like this :
........
........
........
........
........
........
........
........
........
scala> val table = Array.fill(9,8)('.')
table: Array[Array[Char]] = Array(Array(., ., ., ., ., ., ., .), Array(., ., ., ., ., ., ., .),
Array(., ., ., ., ., ., ., .), Array(., ., ., ., ., ., ., .), Array(., ., ., ., ., ., ., .),
Array(., ., ., ., ., ., ., .), Array(., ., ., ., ., ., ., .), Array(., ., ., ., ., ., ., .),
Array(., ., ., ., ., ., ., .))
You can use print
, println
, and foreach
for the desired effect:
table foreach { row => row foreach print; println }
You can also use the mkString
method on collections, which joins the elements of the list (either with no delimeter, or with an overload that provides a string delimeter):
print(table.map(_.mkString).mkString("\n"))
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