scala> //////////////////////////////////////////////////////////////// scala> // head : Get the first element scala> //////////////////////////////////////////////////////////////// scala> val l1 = List(1, 2, 3) //#343 l1: List[Int] = List(1, 2, 3) scala> val hd = l1.head hd: Int = 1 scala> scala> val l1 = List() l1: List[Nothing] = List() scala> val hd = l1.head java.util.NoSuchElementException: head of empty list at scala.collection.immutable.Nil$.head(List.scala:420) at scala.collection.immutable.Nil$.head(List.scala:417) ... 48 elided scala> scala> //////////////////////////////////////////////////////////////// scala> // tail : Get all elements except first scala> //////////////////////////////////////////////////////////////// scala> val l1 = List(1, 2, 3) l1: List[Int] = List(1, 2, 3) scala> val tl = l1.tail tl: List[Int] = List(2, 3) scala> scala> val l1 = List(1) l1: List[Int] = List(1) scala> val tl = l1.tail tl: List[Int] = List() scala> scala> val l1 = List() l1: List[Nothing] = List() scala> val t1 = l1.tail java.lang.UnsupportedOperationException: tail of empty list at scala.collection.immutable.Nil$.tail(List.scala:422) at scala.collection.immutable.Nil$.tail(List.scala:417) ... 48 elided scala> scala> //////////////////////////////////////////////////////////////// scala> // isEmpty : Check if a List is empty of not scala> //////////////////////////////////////////////////////////////// scala> val l1 = List(1, 2, 3) l1: List[Int] = List(1, 2, 3) scala> val is = l1.isEmpty is: Boolean = false scala> scala> val l1 = List() l1: List[Nothing] = List() scala> val is = l1.isEmpty is: Boolean = true