How do I append data in a list?



How do I append data in a list?..

Answer / Akshita Mishra

In Scala, you can append data to a List using the :: (cons) operator or the ++ (append) operator. Here's an example:nn```scalanval list1 = List(1, 2, 3)nval newList = list1 :+ 4 // Using the cons operatorn// Ornval newList = list1 ++ List(4) // Using the append operator

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Scala Interview Questions

What is scala closure?

1 Answers  


What is a class in scala?

1 Answers  


What are the four types of scala identifiers ?

1 Answers  


What is Range in Scala? How to create a Range in Scala?

1 Answers  


What is a multiline expression in scala?

1 Answers  


What is a constructor in scala?

1 Answers  


What is Either in Scala? What are Left and Right in Scala? Explain Either/Left/Right Design Pattern in Scala?

1 Answers  


What are the differences between Array and ArrayBuffer in Scala?

1 Answers  


What is finally in scala?

1 Answers  


What is a companion object in scala?

1 Answers  


What is the result of x+y*z and why?

1 Answers  


Explain how to create arrays?

1 Answers  


Categories