Scala Set find() method with example Last Updated : 18 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The find() method is utilized to find the first element of the set that satisfies the given predicate if present. Method Definition: def find(p: (A) => Boolean): Option[A] Return Type: It returns the first element of the set which satisfies the given predicate. Example #1: Scala // Scala program of find() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set(5, 12, 3, 13) // Applying find method val result = s1.find(_ == 3) // Displays output println(result) } } Output: Some(3) Example #2: Scala // Scala program of find() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set(5, 12, 3, 13) // Applying find method val result = s1.find(_ == 10) // Displays output println(result) } } Output: None Comment More infoAdvertise with us Next Article Scala Set find() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Scala-Set +1 More Similar Reads Scala Stack find() method with example In Scala Stack class, the find() method is utilized to return an element that satisfies a given predicate in the stack. Method Definition: def find(p: (A) => Boolean): Option[A] Return Type: It returns the first element that satisfies a given predicate if present or else it returns None. Example 2 min read Scala TreeSet find() method with example In Scala TreeSet class, the find() method is utilized to return an element that satisfies a given predicate in the TreeSet. Method Definition: def find(p: (A) => Boolean): Option[A] Return Type: It returns the first element that satisfies a given predicate if present or else it returns None. Exam 2 min read Scala Set init() method with example The init() method is utilized to find all the elements of the set except the last one. Method Definition: def init: Set[A] Return Type: It returns all the elements of the set except the last one. Example #1: Scala // Scala program of init() // method // Creating object object GfG { // Main method de 1 min read Scala SortedSet find() method with example The find() method is utilized to find the first element of the SortedSet that satisfies the given predicate if present. Method Definition: def find(p: (A) => Boolean): Option[A] Return Type: It returns the first element of the SortedSet which satisfies the given predicate. Example #1: Scala // Sc 1 min read Scala Set +() method with example The +() method is utilized to create a new set with an additional element unless the element is already present. Method Definition: def +(elem: A): Set[A] Return Type: It returns a new set with an additional element unless the element is already present. Example #1: Scala // Scala program of +() // 1 min read Like