How to skip only first element of List in Scala

In Scala, list is defined under scala.collection.immutable package. A list is a collection of same type elements which contains immutable data. Let’s see how to print the element of given List, by skipping the first item in Scala.

List in Scala contains many suitable methods to perform simple operations like head(), tail(), isEmpty(). Coming to list, tail() method is used to skip the first element of the list.
below are examples to skip only first element of List.

Example :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program to skip only first element of List
import scala.collection.immutable._
  
// Creating object 
object GFGobject
    // Main method 
    def main(args:Array[String]) 
    
        // Creating and initializing immutable lists 
        val mylist: List[String] = List("Geeks", "For", "geeks", "is",
                                          "a", "fabulous", "portal")
   
        println(mylist.tail) 
  
    }
}

chevron_right


Output:



List(For, geeks, is, a, fabulous, portal)

Example :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program to skip only first element of List
import scala.collection.immutable._
  
// Creating object 
object GFG 
    // Main method 
    def main(args:Array[String]) 
    
        // range from 10 to 19
        val myList = List.range(10, 19)
        println(myList) 
  
        println("Using tail() method: " + myList.tail)
    
}     

chevron_right


Output:

List(10, 11, 12, 13, 14, 15, 16, 17, 18)
Using tail() method: List(11, 12, 13, 14, 15, 16, 17, 18)


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.