Open In App

Scala List :::() operator with example

Improve
Improve
Like Article
Like
Save
Share
Report

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:




// Scala program of :::()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating two lists
        val m1 = List(1, 2, 3)
        val m2 = List(4, 5, 6)
          
        // Applying ::: operator
        val res = m1.:::(m2)
          
        // Displays output
        println(res)
      
    }
}


Output:

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

Example #2:




// Scala program of :::()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating two lists
        val m1 = List(1, 2, 3)
        val m2 = List()
          
        // Applying ::: operator
        val res = m1.:::(m2)
          
        // Displays output
        println(res)
      
    }
}


Output:

List(1, 2, 3)


Last Updated : 26 Jul, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads