Scala List ::() operator with example
The ::() operator in Scala is utilized to add an element to the beginning of the List.
Method Definition: def ::(x: A): List[A]
Return Type: It returns the stated list after adding an element to the beginning of it.
Example #1:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 1 , 2 , 3 )
val res = m 1 . :: ( "5" )
println(res)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 1 , 2 , 3 )
val res = m 1 . :: ( "1" )
println(res)
}
}
|
Last Updated :
26 Jul, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...