本文介绍了在 Scala 中打印数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用最基本的 Scala 操作时遇到问题,这让我很抓狂.
val a = Array(1,2,3)println(a) 结果是 [I@1e76345println(a.toString()) 结果是 [I@1e76345println(a.toString) 结果是 [I@1e76345
谁能告诉我如何在不编写自己的函数的情况下打印数组,因为这很愚蠢.谢谢!
解决方案
mkString
将集合(包括 Array
)逐个元素转换为字符串表示.
mkString
>
println(a.mkString(" "))
可能就是你想要的.
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!
解决方案
mkString
will convert collections (including Array
) element-by-element to string representations.
println(a.mkString(" "))
is probably what you want.
这篇关于在 Scala 中打印数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!