Scala ListSet takeWhile() method with example Last Updated : 13 Feb, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report In Scala ListSet, takeWhile() method is utilized to find the elements from the list as long as the stated condition is satisfied. Method Definition: def takeWhile(p: (A) => Boolean): ListSet[A] Return Type: It returns the elements from the list as long as the stated condition is satisfied. Example 1: Scala // Scala program of takeWhile() // method import scala.collection.immutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a listset val m1 = ListSet(1, 2, 3, 4, 5, 7) // Applying takeWhile method val result = m1.takeWhile(_ > 3) // Displays output println(result) } } Output:ListSet(4, 5, 7) Example 2: Scala // Scala program of takeWhile() // method import scala.collection.immutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a listset val m1 = ListSet(1, 2, 3, 4, 5, 7) // Applying takeWhile method val result = m1.takeWhile(_ > 7) // Displays output println(result) } } Output:ListSet() Comment More infoAdvertise with us Next Article Scala Iterator take() method with example I IshwarGupta Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala List takeWhile() method with example The takeWhile() method is utilized to find the elements from the list as long as the stated condition is satisfied. Method Definition: def takeWhile(p: (A) => Boolean): List[A] Return Type: It returns the elements from the list as long as the stated condition is satisfied. Example #1: Scala // Sc 1 min read Scala List take() method with example The take() method belongs to the value member of the class List. It is utilized to take the first n elements from the list. Method Definition: deftake(n: Int): List[A] Where, n is the number of elements to be taken from the list. Return Type:It returns a list containing only the first n elements fro 1 min read Scala List takeRight() method with example The takeRight() method is utilized to select the last 'n' elements of the list. Method Definition: def takeRight(n: Int): List[A] Return Type: It returns the last 'n' elements of the list. Example #1: Scala // Scala program of takeRight() // method // Creating object object GfG { // Main method def 1 min read Scala Iterator take() method with example The take() method belongs to the concrete value member of the class Abstract Iterator. It is utilized to select the first n elements of the stated iterator. Method Definition: def take(n: Int): Iterator[A] Where, n is the number of element to take from the given iterator. Return Type: It returns the 2 min read Scala ListSet sum() method with example In Scala ListSet, sum() method is utilized to add all the elements of the stated listSet. Method Definition: def sum(num: math.Numeric[B]): B Return Type: It returns the sum of all the elements of the listSet. Example 1: Scala // Scala program of sum() // method import scala.collection.immutable._ / 1 min read Scala ListSet max() method with example In Scala ListSet, max() method is utilized to find the largest element of all the elements in the stated list. Method Definition: def max[B >: A](implicit ord: math.Ordering[B]): A Return Type: It returns the largest of all the elements in the stated listSet. Example 1: Scala // Scala program of 1 min read Like