Javatpoint Logo
Javatpoint Logo

Java HashSet remove() Method

The remove() is a method of Java HashSet class which removes the specified element from this set if it is present.

Syntax

Following is the declaration of remove() method:

Parameter

Parameter Description Required/Optional
o It is the object which will be removed to this set, if present. Required

Returns

The remove() method returns true if the set contained the specified element.

Exceptions

NA

Compatibility Version

Java 1.2 and above

Example 1

Test it Now

Output:

HashSet: [Vijay, Ravi, Aman, Ajay]
HashSet after removing elements: [Ravi, Aman, Ajay]

Example 2

Test it Now

Output:

HashSet: [98, 67, 24, 45]
HashSet after removing elements: [67, 45]

Example 3

Test it Now

Output:

103 Operating System Galvin Wiley 6
101 Let us C Yashwant Kanetkar BPB 8
102 Data Communications & Networking Forouzan Mc Graw Hill 4
Books after remove method:
103 Operating System Galvin Wiley 6
101 Let us C Yashwant Kanetkar BPB 8





Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA