scala – List operations

head returns the first element of a list

tail returns a list consisting of all elements except the first

isEmpty returns true if the list is empty

The head and tail methods are defined only for non-empty lists

 Nil.head 

Nil.head java.util.NoSuchElementException: head of empty list

 

Note – Nil is the empty list 

val empty_1:List[Nothing]=Nil

Leave a comment