scala> // 'List' type is covariant #341 scala> // ie A is a Subtype of B scala> // List[A] is a Subtype of List[B] scala> scala> //////////////////////////////////////////////////////////////// scala> // Create an Empty List scala> //////////////////////////////////////////////////////////////// scala> scala> // Ex 1 : Using List() scala> // An empty list is List[Nothing] #341 scala> // Note : Nothing is the bottom type of Scala Hierarchy scala> val l1 = List() l1: List[Nothing] = List() scala> scala> // Ex 2 : Using Nil scala> val l1 = Nil l1: scala.collection.immutable.Nil.type = List() scala> scala> //////////////////////////////////////////////////////////////// scala> // Create a Non-empty List scala> //////////////////////////////////////////////////////////////// scala> // Ex 1 : Using Wrapper scala> val l1: List[String] = List("ex1", "ex2") l1: List[String] = List(ex1, ex2) scala> scala> // Ex 2 : Using Cons Operator & Nil scala> // Syntax : x :: xs scala> // x = Element scala> // xs = List of elements scala> val l1 = 1 :: (2 :: (3 :: Nil)) l1: List[Int] = List(1, 2, 3) scala> scala> val l1 = 1 :: 2 :: 3 :: Nil l1: List[Int] = List(1, 2, 3)