Scala Set &() method with example Last Updated : 18 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The &() method is utilized to create a new set consisting of all elements that are present in both the given sets. Method Definition: Return Type: It returns a new set consisting of all elements that are present in both the given sets. Example #1: Scala // Scala program of &() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set(41, 12, 23, 43, 1, 72) val s2 = Set(1, 100, 5, 12, 23) // Applying &() method val result = s1.&(s2) // Display output print(result) } } Output: Set(1, 12, 23) Example #2: Scala // Scala program of &() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set(1, 3, 5, 7) val s2 = Set(2, 4, 6, 8) // Applying &() method val result = s1.&(s2) // Display output print(result) } } Output: Set() Comment More infoAdvertise with us Next Article Scala Set &~() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Scala-Set +1 More Similar Reads Scala Set &~() method with example The &~() method is utilized to create a new set consisting of elements after the difference between two given sets. Method Definition: def &~(that: Set[A]): Set[A] Return Type: It returns a set consisting of elements after the difference between two given sets. Example #1: Scala // Scala pro 1 min read Scala TreeSet &() method with example In Scala TreeSet class, the &() method is utilized to return a new TreeSet containing elements that are present in both the given TreeSets. Method Definition: def &(that: TreeSet[A]): TreeSet[A] Return Type: It returns a new TreeSet containing elements that are present in both the given Tree 2 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 Scala Set ++() method with example The ++() method is utilized to add elements of one set to another set. Method Definition: def ++(elems: A): Set[A] Return Type: It returns a new set containing elements of both the sets. Example #1: Scala // Scala program of ++() // method // Creating object object GfG { // Main method def main(args 1 min read Scala TreeSet &~() method with example In Scala TreeSet class, the &~() method is utilized to return a new TreeSet which contains the difference between two TreeSets. Method Definition: def &~(that: TreeSet[A]): TreeSet[A] Return Type: It returns a new TreeSet which contains the difference between two TreeSets. Example #1: Scala 2 min read Scala Set -() method with example The -() method is utilized to creates a new set with a given element removed from the set. Method Definition: def -(elem: A): Set[A] Return Type: It returns a new set with a given element removed from the set. Example #1: Scala // Scala program of -() // method // Creating object object GfG { // Mai 1 min read Like