Scala Queue apply() method with example Last Updated : 18 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The apply() method is utilized to find the element at any given index in a queue. Method Definition: def apply(idx: Int): A Return Type: It returns the element at the given index of the queue. Example #1: Scala // Scala program of apply() // method // Import Queue import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a queue val q1 = Queue(10, 11, 12, 13, 14) // Print the queue println(q1) // Applying apply() method val result = q1.apply(0) // Display output print("Element at index 0 : " + result) } } Output: Queue(10, 11, 12, 13, 14) Element at index 0 : 10 Example #2: Scala // Scala program of apply() // method // Import Queue import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a queue val q1 = Queue(10, 11, 12, 13, 14) // Print the queue println(q1) // Applying apply() method val result = q1.apply(2) // Display output print("Element at index 2 : " + result) } } Output: Queue(10, 11, 12, 13, 14) Element at index 2 : 12 Comment More infoAdvertise with us Next Article Scala Queue apply() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala Queue +=() method with example The +=() method is utilized to add an element at the back of a given queue. Method Definition: def +=(elem: A): Queue.this.type Return Type: It returns the given queue with an element added at its back. Example #1: Scala // Scala program of +=() // method // Import Queue import scala.collection.muta 1 min read Scala Queue +=:() method with example The +=:() method is utilized to add an element at the front of a queue. Method Definition: def +=:(elem: A): Queue.this.type Return Type: It returns the given queue with an element added at its front. Example #1: Scala // Scala program of +=:() // method // Import Queue import scala.collection.mutab 1 min read Scala Queue :+() method with example The :+() method is utilized to return a new queue with an element added at the back of the given queue. Method Definition: def:+[B >: A](elem: B): Queue[B] Return Type: It returns a new queue with an element added at the back of the given queue. Example #1: Scala // Scala program of :+() // metho 1 min read Scala Queue ++=() method with example The ++=() method is utilized to add element of a queue at the back of another queue. Method Definition: def ++=(xs: IterableOnce[A]): Queue.this.type Return Type: It returns the given queue with elements of another queue added at its end. Example #1: Scala // Scala program of ++=() // method // Impo 1 min read Scala Queue +:() method with example The +:() method is utilized to return a new queue with an element added at the front of the given queue. Method Definition: def +:[B >: A](elem: B): Queue[B] Return Type: It returns a new queue with an element added at the front of the given queue. Example #1: Scala // Scala program of +:() // me 1 min read Like