Scala List dropRight() method with example
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) } } |
chevron_right
filter_none
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) } } |
chevron_right
filter_none
Output:
List()
Recommended Posts:
- Scala Set dropRight() method with example
- Scala Map dropRight() method with example
- Scala SortedMap dropRight() method with example
- Scala TreeSet dropRight() method with example
- Scala SortedSet dropRight() method with example
- Scala Queue dropRight() method with example
- Scala Stack dropRight() method with example
- Scala List sum() method with example
- Scala List max() method with example
- Scala List map() method with example
- Scala List contains() method with example
- Scala List take() method with example
- Scala List min() method with example
- Scala List addString() method with example
- Scala List mkString() method with example
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.



