In Scala, which of the following statements about the lists is true:
1. A list is an immutable recursive data structure while array is a sequential mutable data structure.
2. The lists are covariant while arrays are invariant.
3. A list is a fixed-sized data structure while an array is variable-sized data structure.
4. A list can only be concatenated by using “:::” operator.
object Demo {
def main(args: Array[String]) {
val x = Demo(7)
println(x)
x match {
case Demo(num) => println(x + " is bigger two times than " + num)
case _ => println("I cannot calculate")
}
}
def apply(x: Int) = x * 4
def unapply(z: Int): Option[Int] =
if (z % 2 == 0) Some(z / 2)
else None
}
In Scala, which of the following statements about the operation xs mkString (pre, sep, post) is true:
1. It takes three arguments.
2. A prefix string pre should be displayed in front of all the elements on which this operation is performed.
3. A separator string sep should be displayed between the successive elements on which this operation is performed.