Scala ++ example (concatenating two lists)

The ++ operator lets you concatenate two lists:

List(1, 2, 3) ++ List(4, 5, 6)

res59: List[Int] = List(1, 2, 3, 4, 5, 6)

This also works as expected with option classes:

List(1,2,3) ++ Some(4)
res60: List[Int] = List(1, 2, 3, 4)

List(1,2,3) ++ None
res62: List[Int] = List(1, 2, 3)

Leave a Reply

Your email address will not be published. Required fields are marked *