Java TreeSet remove() method

The remove() method of TreeSet class is used to delete/remove elements from the set.

Syntax:

Parameter:

o - element to be removed from the set.

Return:

It returns true if set contain specified element

Example 1

Output:

TreeSet: [ 1, 2, 5, 8, 10 ]
TreeSet: true
TreeSet: [1, 2, 8, 10 ]

Example 2

Output:

TreeSet: [ A, B, a, b ]
TreeSet: true
TreeSet: [A, a, b ]

Example 3

Output:

TreeSet: [ A, B, a, b ] [ 1, 3, 6, 9 ]
TreeSet: true
TreeSet: [ A, B, a, b ] [ 1, 6, 9 ]
TreeSet: true
TreeSet: [ B, a, b ] [ 1, 6, 9 ]

Example 4

Output:

Javac TreeSetremove4.java
Java TreeSetremove4
TreeSet: [1, 3, 6, 9, A, B, a, b]
TreeSet: false
TreeSet: [1, 3, 6, 9, A, B, a, b]