Scala TreeSet max() method with example Last Updated : 11 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The max() method is utilized to return the largest method of the TreeSet. Method Definition: def max: A Return Type: It returns the largest element of the TreeSet. Example #1: Scala // Scala program of max() // method // Import TreeSet import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating TreeSet val q1 = TreeSet(1, 2, 3, 4, 5) // Print the TreeSet println(q1) // Applying max method val result = q1.max // Displays output print("Largest element in the TreeSet: " + result) } } Output: TreeSet(1, 2, 3, 4, 5) Largest element in the TreeSet: 5 Example #2: Scala // Scala program of max() // method // Import TreeSet import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating TreeSet val q1 = TreeSet("u", "a", "i", "o", "e") // Print the TreeSet println(q1) // Applying max method val result = q1.max // Displays output print("Largest element in the TreeSet: " + result) } } Output: TreeSet(a, e, i, o, u) Largest element in the TreeSet: u Comment More infoAdvertise with us Next Article Scala TreeSet max() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala Set max() method with example The max() method is utilized to find the largest element of all the elements in the set. Method Definition: def max: A Return Type: It returns the largest of all the elements in the set. Example #1: Scala // Scala program of max() // method // Creating object object GfG { // Main method def main(arg 1 min read Scala TreeSet last() method with example The last() method is utilized to return the last element of the TreeSet. Method Definition: def last: A Return Type: It returns the last element of the TreeSet. Example #1: Scala // Scala program of last() // method // Import TreeSet import scala.collection.mutable._ // Creating object object GfG { 1 min read Scala SortedSet max() method with example The max() method is utilized to find the largest element of all the elements in the SortedSet. Method Definition: def max: A Return Type: It returns the largest of all the elements in the SortedSet. Example #1: Scala // Scala program of max() // method import scala.collection.immutable.SortedSet // 1 min read Scala Stack max() method with example In Scala Stack class, the max() method is utilized to return the largest method of the stack. Method Definition: def max: A Return Type: It returns the largest element of the stack. Example #1: Scala // Scala program of max() // method // Import Stack import scala.collection.mutable._ // Creating ob 1 min read Scala Short max() method with example The max() method is utilized to find the maximum of the two specified Short types. Method Definition: def max(that: Short): Short Return Type: It returns the number of type Short with the maximum value. Example: 1# Scala // Scala program of max() // method // Creating object object GfG { // Main met 1 min read Like