Open In App
Related Articles

Scala List dropRight() method with example

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
The dropRight() method is utilized to find all the elements of the list except the last n elements.
Method Definition: def dropRight(n: Int): List[A] Return Type: It returns all the elements of the list except the last n elements.
Example #1:
// Scala program of dropRight()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a list
        val m1 = List(1, 1, 3, 3, 3, 5, 4, 5, 2)
          
        // Applying dropRight method
        val res = m1.dropRight(3)
          
        // Displays output
        println(res)
      
    }
}

                    
Output:
List(1, 1, 3, 3, 3, 5)
Example #2:
// Scala program of dropRight()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a list
        val m1 = List(1, 1, 3, 3, 3, 5, 4, 5, 2)
          
        // Applying dropRight method
        val res = m1.dropRight(10)
          
        // Displays output
        println(res)
      
    }
}

                    
Output:
List()


Last Updated : 26 Jul, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads