// Scala - Sets object Demo { val myset: Set[Int] = Set(1,2,5,8,9,6,4); val myset2: Set[Int] = Set(4,2,9,18,19,16,14); val names: Set[String] = Set("Max", "Tom", "John"); def main(args: Array[String]) { println(myset + 10); println(names("Maxxxx")); println(myset.head); println(myset.tail); println(myset.isEmpty); println(myset ++ myset2); println(myset.++(myset2)) println(myset.&(myset2)); println(myset.intersect(myset2)); println(myset.max); println(myset.min); myset.foreach(println); for (name <- names) { println(name); } } } /* OUTPUT: Set(5, 10, 1, 6, 9, 2, 8, 4) false 5 Set(1, 6, 9, 2, 8, 4) false Set(5, 14, 1, 6, 9, 2, 18, 16, 8, 19, 4) Set(5, 14, 1, 6, 9, 2, 18, 16, 8, 19, 4) Set(9, 2, 4) Set(9, 2, 4) 9 1 5 1 6 9 2 8 4 Max Tom John */
Leave a Reply