Scala Mutable SortedMap copyToArray() method with example Last Updated : 04 May, 2020 Comments Improve Suggest changes Like Article Like Report The copyToArray() method is utilized in copying pair of keys of the SortedMap to an Array. Method Definition: def copyToArray(xs: Array[(A, B)]): Unit Return Type: It returns the keys of the SortedMap to an array. Example #1: Scala // Scala program of copyToArray() // method import scala.collection.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap("geeks" -> 5, "for" -> 3, "cs" -> 2) // Creating Array val x: Array[Any] = Array(0, 0, 0, 0, 0) // using 'copyToArray' method m1.copyToArray(x) // Displays keys copied in // the Array for(m2 <-x) println(m2) } } Output: (cs, 2) (for, 3) (geeks, 5) 0 0 So, here the keys are copied to the array. Example #2: Scala // Scala program of copyToArray() // method import scala.collection.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap("geeks" -> 5, "for" -> 3, "geeks" -> 5) // Creating Array val x: Array[Any] = Array(0, 0, 0, 0, 0) // using 'copyToArray' method m1.copyToArray(x) // Displays keys copied in // the Array for(m2 <-x) println(m2) } } Output: (for, 3) (geeks, 5) 0 0 0 Here, the identical keys are removed. Comment More infoAdvertise with us Next Article Scala Mutable SortedMap copyToArray() method with example S Shivam_k Follow Improve Article Tags : Python Scala Scala Mutable-collections Scala Mutable-SortedMap Practice Tags : python Similar Reads Scala SortedMap copyToArray() method with example The copyToArray() method is utilized in copying pair of keys of the SortedMap to an Array. Method Definition: def copyToArray(xs: Array[(A, B)]): Unit Return Type: It returns the keys of the SortedMap to an array. Example #1: Scala // Scala program of copyToArray() // method import scala.collection. 2 min read Scala Mutable SortedMap empty() method with example The empty() method is utilized to make the SortedMap empty. Method Definition: def empty: SortedMap[A, B] Return Type: It returns an empty SortedMap. Example #1: Scala // Scala program of empty() // method import scala.collection.SortedMap // Creating object object GfG { // Main method def main(args 1 min read Scala Mutable SortedMap count() method with example The count() method is utilized to count pair of keys in the SortedMap. Method Definition: def count(p: ((A, B)) => Boolean): Int Return Type: It returns the number of keys present in the SortedMap that satisfies the given predicate. Example #1: Scala // Scala program of count() // method import s 1 min read Scala Mutable SortedMap drop() method with example The drop() method is utilized to delete the first 'n' elements. Method Definition: def drop(n: Int): SortedMap[A, B] Return Type: It returns all the elements of the SortedMap except the first 'n' elements. Example #1: Scala // Scala program of drop() // method import scala.collection.SortedMap // Cr 1 min read Scala Mutable SortedMap apply() method with example The apply() is utilized to search a key in the stated SortedMap. Method Definition: m1.apply("key") Here m1 is SortedMap. Return Type: It returns the value of the key to be searched. Example #1: Scala // Scala program of apply() // method import scala.collection.SortedMap // Creating object object G 1 min read Scala Mutable SortedMap dropRight() method with example The dropRight() method is utilized to delete the last 'n' elements. Method Definition: def dropRight(n: Int): SortedMap[A, B] Return Type: It returns all the elements of the SortedMap except the last 'n' elements. Example #1: Scala // Scala program of dropRight() // method import scala.collection.So 1 min read Scala SortedSet copyToArray() method with example The copyToArray() method is utilized in copying the elements of the SortedSet to an Array. Method Definition: def copyToArray(xs: Array[A], start: Int, len: Int): Unit Parameters: xs: It denotes the array where elements are copied. start: It denotes the starting index for the copy to takes place. It 2 min read Scala Mutable SortedMap equals() method with example The equals() method is utilized to check whether the two SortedMaps have the same key-values pair or not. Method Definition: def equals(that: Any): Boolean Return Type: It returns true if the key-value pairs of both the SortedMaps are same else it returns false. Example #1: Scala // Scala program of 1 min read Scala Mutable SortedMap addString() method with example The addString() method is utilized to add the elements of the SortedMap to the String Builder. Method Definition: def addString(b: StringBuilder): StringBuilder Return Type: It returns the elements in the String Builder. Example #1: Scala // Scala program of addString() // method import scala.collec 1 min read Scala Mutable SortedMap dropWhile() method with example The dropWhile() method is utilized to delete the elements until the stated condition is satisfied. Method Definition: def dropWhile(p: ((A, B)) => Boolean): SortedMap[A, B] Return Type: It returns the longest suffix of elements of the stated SortedMap whose first element does not satisfies the pr 1 min read Like