在 Scala 中组合数组 [英] Combining Arrays in Scala
本文介绍了在 Scala 中组合数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有 DerivedType1:BaseType
和 DerivedType2:BaseType
和 Array[DerivedType1]
和 Array[DerivedType2]
,将它们组合成 Array[BaseType]
的最简洁方法是什么?
If I have DerivedType1:BaseType
and DerivedType2:BaseType
and Array[DerivedType1]
and Array[DerivedType2]
, what's the most succinct way of combining them into Array[BaseType]
?
推荐答案
在 Array
上使用 ++
方法.
Use the ++
method on Array
.
scala> class A; class B extends A; class C extends A
defined class A
defined class B
defined class C
scala> Array(new B, new B) ++ Array(new C, new C)
res33: Array[A] = Array(B@b7501b, B@ec5359, C@1540d0c, C@124a927)
这篇关于在 Scala 中组合数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文