 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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("\nUpdated LinkedHashSet..."); System.out.println(hashSet); } }  Output
LinkedHashSet... [10, 20, 30, 40, 50, 60] Updated LinkedHashSet... [20, 30, 40, 50, 60]
Advertisements
 