Related Articles

Related Articles

Scala Queue reverse() method with example
  • Last Updated : 29 Oct, 2019

The reverse() method is utilized to return a queue with the reverse order.

Method Definition: def reverse: Queue[A]

Return Type: It returns a queue with the reverse order.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of reverse() 
// method 
  
// Import Queue  
import scala.collection.mutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a queue 
        val q1 = Queue(1, 2, 3, 4, 5
          
        // Print the queue
        println(q1)
          
        // Applying reverse method 
        val result = q1.reverse
          
        // Display output
        print("Reversed queue: " + result)
          
    

chevron_right


Output:

Queue(1, 2, 3, 4, 5)
Reversed queue: Queue(5, 4, 3, 2, 1)

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of reverse() 
// method 
  
// Import Queue  
import scala.collection.mutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a queue 
        val q1 = Queue(5, 2, 13, 7, 1, 3
          
        // Print the queue
        println(q1)
          
        // Applying reverse method 
        val result = q1.reverse
          
        // Display output
        print("Reversed queue: " + result)
          
    

chevron_right


Output:

Queue(5, 2, 13, 7, 1, 3)
Reversed queue: Queue(3, 1, 7, 13, 2, 5)



My Personal Notes arrow_drop_up
Recommended Articles
Page :