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:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 1 , 2 , 3 )
val res = m 1 .+( "10" )
println(res)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = List()
val res = m 1 .+( "10" )
println(res)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...