You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*TreeSet is a class in Java that implements the Set interface. It is used to store a sorted collection of unique elements, meaning it does not allow duplicate values.*
3
+
*TreeSet internally uses a Red-Black tree data structure to maintain the elements in sorted order.*
4
+
5
+
## There are many methods related to TreeSet Here are most common that are used
6
+
7
+
### 1. add(E element):
8
+
* This method adds the specified element to the TreeSet if it is not already present. If the element is already present, the set remains unchanged.
9
+
10
+
### 2. contains(Object o):
11
+
* This method returns true if the TreeSet contains the specified element; otherwise, it returns false.
12
+
13
+
### 3. remove(Object o):
14
+
* This method removes the specified element from the TreeSet if it is present. Returns true if the element was present and successfully removed; otherwise, returns false.
15
+
16
+
### 4. size():
17
+
* This method returns the number of elements in the TreeSet.
18
+
19
+
### 5. isEmpty():
20
+
* This method returns true if the TreeSet contains no elements; otherwise, returns false.
21
+
22
+
### 6. clear():
23
+
* This method removes all elements from the TreeSet.
0 commit comments