- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove specified element from Java LinkedHashSet
To remove a specified element from LinkedHashSet, use the remove() and include the element you want to remove as a parameter.
First, set LinkedHashSet and add elements −
LinkedHashSet<Integer> hashSet = new LinkedHashSet<Integer>(); hashSet.add(10); hashSet.add(20); hashSet.add(30); hashSet.add(40); hashSet.add(50); hashSet.add(60);
Let us now remove an element −
hashSet.remove(10);
The following is an example to remove specified element from LinkedHashSet −
Example
import java.util.LinkedHashSet; public class Demo { public static void main(String[] args) { LinkedHashSet<Integer> hashSet = new LinkedHashSet<Integer>(); hashSet.add(10); hashSet.add(20); hashSet.add(30); hashSet.add(40); hashSet.add(50); hashSet.add(60); System.out.println("LinkedHashSet..."); System.out.println(hashSet); hashSet.remove(10); System.out.println("
Updated LinkedHashSet..."); System.out.println(hashSet); } }
Output
LinkedHashSet... [10, 20, 30, 40, 50, 60] Updated LinkedHashSet... [20, 30, 40, 50, 60]
- Related Articles
- Remove all elements from Java LinkedHashSet
- Remove specified element from HashSet in Java
- Remove specified element from TreeSet in Java
- Remove the specified element from a HashSet in C#
- Fetch key-valuepair from Java LinkedHashSet
- Check if a particular element exists in Java LinkedHashSet
- Remove the element with the specified key from a SortedList in C#
- Remove the element with the specified key from the Hashtable in C#
- Remove an element from IdentityHashMap in Java
- How to remove element from the specified index of the List in C#?
- Remove an element from a Queue in Java
- Remove an element from a Stack in Java
- Remove single element from a HashSet in Java
- How to remove element from ArrayList in Java?
- Remove element at specified index of Collection in C#

Advertisements