The dropRight() is utilized to return all elements except last ‘n’ elements.
Method Definition: def dropRight(n: Int): Set[A]
Return Type: It returns a set containing all elements except last ‘n’ elements.
Example #1:
// Scala program of dropRight() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating sets val s1 = Set(1, 2, 3, 4, 5) // Applying dropRight method val s2 = s1.dropRight(1) // Displays output for(elem <- s2) println(elem) } } |
chevron_right
filter_none
Output:
5 1 2 3
Example #2:
// Scala program of dropRight() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating sets val s1 = Set(1, 2, 3, 4, 5) // Applying dropRight method val s2 = s1.dropRight(2) // Displays output for(elem <- s2) println(elem) } } |
chevron_right
filter_none
Output:
5 1 2
Recommended Posts:
- Scala Map dropRight() method with example
- Scala List dropRight() method with example
- Scala Queue dropRight() method with example
- Scala SortedSet dropRight() method with example
- Scala SortedMap dropRight() method with example
- Scala Stack dropRight() method with example
- Scala TreeSet dropRight() method with example
- Scala Mutable SortedMap dropRight() method with example
- Scala BitSet dropRight() method with example
- Scala mutable SortedSet dropRight() method
- Scala immutable TreeSet dropRight() method
- Scala Set &() method with example
- Scala Set equals() method with example
- Scala Set drop() method with example
- Scala Set dropWhile() method with example
- Scala Set diff() method with example
- Scala Set copyToArray() method with example
- Scala Set subsetOf() method with example
- Scala Set ++() method with example
- Scala Set splitAt() 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.

