Related Articles

Related Articles

Scala List +() operator with example
  • Last Updated : 26 Jul, 2019

The +() operator in Scala is utilized to append an element to the list.

Method Definition: def +(elem: A): List[A]

Return Type: It returns a list of the stated elements after appending it to an another element.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

List(1, 2, 3)10

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of +()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a list
        val m1 = List()
          
        // Applying + operator
        val res = m1.+("10")
          
        // Displays output
        println(res)
      
    }
}

chevron_right


Output:

List()10



My Personal Notes arrow_drop_up
Recommended Articles
Page :