1.Basic java example program to remove particular element in linkedhashset
Output:
- boolean remove(Object o) This method used to remove specified element from Linkedhashset.
- package com.removeelementLinkedhashset;
- import java.util.LinkedHashSet;
- import java.util.Iterator;
- public class LinkedHashsetExample{
- public static void main(String[] args) {
- LinkedHashSet<String> linkedhashset = new LinkedHashSet<>();
- linkedhashset.add("Java Interview Questions");
- linkedhashset.add("Java interview program");
- linkedhashset.add("Concept and example program");
- linkedhashset.add("Concept and interview questions");
- linkedhashset.add("Java Quiz");
- System.out.println("LinkedHashSet before removal : " + linkedhashset);
- boolean blnRemoved = linkedhashset.remove("Java Quiz");
- System.out.println("Was Java Quiz removed from LinkedHashSet ? " + blnRemoved);
- System.out.println("LinkedHashSet after removal : ");
- Iterator it=linkedhashset.iterator();
- while(it.hasNext()){
- System.out.println(it.next());
- }
- }
- }
Output:
- LinkedHashSet before removal : [Java Interview Questions, Java interview program, Concept
- and example program, Concept and interview questions, Java Quiz]
- Was Java Quiz removed from LinkedHashSet ? true
- Java Interview Questions
- Java interview program
- Concept and example program
- Concept and interview questions
Bagikan
Remove specified element from Java LinkedHashSet example
4/
5
Oleh
Kris Kimcil