CodesJava

Easy learning with example program codes

Delete specific element from linkedhashset

We can use remove() method to remove the specific element from linkedhashset in java.

Syntax:

linkedHashSet.remove(specifiedElement);

Example:

package com.codesjava;
 
import java.util.LinkedHashSet;
 
public class Test {
  public static void main(String args[]){
	//Create LinkedHashSet
	LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();
        //Add elements to LinkedHashSet
	linkedHashSet.add("Jai");
	linkedHashSet.add("Mahesh");
	linkedHashSet.add("Vikas");
	linkedHashSet.add("Sahil");
	linkedHashSet.add("Sachin");
	linkedHashSet.add("Vijay");
	System.out.println("LinkedHashSet: " + linkedHashSet);
	linkedHashSet.remove("Vikas");
        System.out.println("LinkedHashSet after modification: " + linkedHashSet);
  }
}

Output

LinkedHashSet: [Jai, Mahesh, Vikas, Sahil, Sachin, Vijay]
LinkedHashSet after modification: [Jai, Mahesh, Sahil, Sachin, Vijay]
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status