VOOZH about

URL: https://www.geeksforgeeks.org/scala/scala-immutable-treeset-method-3/

⇱ Scala immutable TreeSet +() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Scala immutable TreeSet +() method

Last Updated : 19 Apr, 2020
In Scala immutable TreeSet class, the +() method is utilised to add an element to the TreeSet unless it is already present.
Method Definition: def +(elem: A): TreeSet[A] Return Type: It returns a new TreeSet with an additional element unless the element is already present.
Example #1:
Output:
TreeSet(a, e, i, o)
After adding an element: TreeSet(a, e, i, o, u)
Example #2:
Output:
TreeSet(1, 2, 4, 5)
After adding an element: TreeSet(1, 2, 3, 4, 5)
Comment
Article Tags:

Explore