Scala Set dropRight() method with example
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 s 1 = Set( 1 , 2 , 3 , 4 , 5 ) // Applying dropRight method val s 2 = s 1 .dropRight( 1 ) // Displays output for (elem < - s 2 ) println(elem) } } |
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 s 1 = Set( 1 , 2 , 3 , 4 , 5 ) // Applying dropRight method val s 2 = s 1 .dropRight( 2 ) // Displays output for (elem < - s 2 ) println(elem) } } |
Output:
5 1 2