Combining two lists in Scala

后端 未结 8 822
北海茫月
北海茫月 2021-01-04 00:58

From 2 lists of the form List[(Int, String):

l1 = List((1,\"a\"),(3,\"b\"))
l2 = List((3,\"a\"),(4,\"c\"))

how can I combine t

8条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-04 01:44

    val a = List(1,1,1,0,0,2)
    val b = List(1,0,3,2)
    
    scala> List.concat(a,b)
    res31: List[Int] = List(1, 1, 1, 0, 0, 2, 1, 0, 3, 2)
    
    (or) 
    
    scala> a.:::(b)
    res32: List[Int] = List(1, 0, 3, 2, 1, 1, 1, 0, 0, 2)
    
    (or) 
    
    scala> a ::: b
    res28: List[Int] = List(1, 1, 1, 0, 0, 2, 1, 0, 3, 2)
    

提交回复
热议问题