Open In App
Related Articles

Scala List drop() method with example

Improve Article
Improve
Save Article
Save
Like Article
Like

The drop() method belongs to the value member of the class List. It is utilized to select all the elements except the first n elements of the list.

Method Definition: def drop(n: Int): List[A]

Where, n is the number of elements to be dropped from the stated sequence.

Return Type: It returns all the elements of the list except the first n ones.

Example #1:




   
// Scala program of drop()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a List 
        val list = List("a", "b", "c", "d", "e", "f")
          
        // Applying drop method 
        val result = list.drop(4)
          
        // Displays output
        println(result)
      
    }
}


Output:

List(e, f)

Example #2:




// Scala program of drop()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a List 
        val list = List(1, 2, 3, 4, 5, 6)
          
        // Applying drop method 
        val result = list.drop(2)
          
        // Displays output
        println(result)
      
    }
}


Output:

List(3, 4, 5, 6)

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 13 Aug, 2019
Like Article
Save Article
Previous
Next
Similar Reads