如何添加数组值a& b(多个值)列表list1
var list1:java.util.List[Array[String]]=List[Array[String]]()
var a=Array[String]("Excellent","Good","Need To Improve")
var b=Array[String]("1","2","3")
list1.add(a)
list1.add(b)
我尝试了这个但是Array值没有添加到List
数组值不会添加到列表
答案 0 :(得分:2)
java.util.ArrayList有两种可能性(可变):
scala> val list = new java.util.ArrayList[Array[String]]()
list: java.util.ArrayList[Array[String]] = []
scala> var a=Array[String]("Excellent","Good","Need To Improve")
a: Array[String] = Array(Excellent, Good, Need To Improve)
scala> var b=Array[String]("1","2","3")
b: Array[String] = Array(1, 2, 3)
scala> list.add(a)
res8: Boolean = true
scala> list.add(b)
res9: Boolean = true
scala> list
res10: java.util.ArrayList[Array[String]] = [[Ljava.lang.String;@4786b9ce, [Ljava.lang.String;@5e10a811]
或者对于scala List(不可变) - 您已分配列表:
scala> var list = List[Array[String]]()
list: List[Array[String]] = List()
scala> list = b :: a :: list
list: List[Array[String]] = List([Ljava.lang.String;@5e10a811, [Ljava.lang.String;@4786b9ce)