Related Articles

Related Articles

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

The splitAt() method is utilized to split the given queue into a prefix/suffix pair of queues at a stated position.

Method Definition: def splitAt(n: Int): (Queue[A], Queue[A])
Where, n is the position at which we need to split.

Return Type: It returns a pair of queues consisting of the first n elements of this queue, and the other elements.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of splitAt() 
// 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
          
        // Print the queue
        println(q1)
          
        // Applying splitAt method 
        val result = q1.splitAt(3)
          
        // Display output
        print(result)
          
    

chevron_right


Output:

Queue(5, 2, 13, 7, 1)
(Queue(5, 2, 13), Queue(7, 1))

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of splitAt() 
// 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
          
        // Print the queue
        println(q1)
          
        // Applying splitAt method 
        val result = q1.splitAt(2)
          
        // Display output
        print(result)
          
    

chevron_right


Output:

Queue(5, 2, 13, 7, 1)
(Queue(5, 2), Queue(13, 7, 1))



My Personal Notes arrow_drop_up
Recommended Articles
Page :