Scala List :::() operator with example
The :::() operator in Scala is utilized to join the List in the argument to the another List.
Method Definition: def :::(prefix: List[A]): List[A]
Return Type: It returns a list after joining one list to the another one.
Example #1:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 1 , 2 , 3 )
val m 2 = List( 4 , 5 , 6 )
val res = m 1 . ::: (m 2 )
println(res)
}
}
|
Output:
List(4, 5, 6, 1, 2, 3)
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 1 , 2 , 3 )
val m 2 = List()
val res = m 1 . ::: (m 2 )
println(res)
}
}
|
Last Updated :
26 Jul, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...