How to remove the single element from the LinkedHashSet?
Previous | Home | Next |
This program will shows how to remove the particular element from the LinkedHashSet.
In This program we will saw how to remove the particular element from the Set using the Remove() method of the LinkedHashSet.
public boolean remove( object obj) is used here to remove the particular element .if the lememnt is present in the Set.it will shows the result in the boolean true/false.
To remove element just do thisObject obj=Lhst.remove("13");and then call the obj in println to check the element will remove or not if it removes it will shows the result true otherwise false.
package Example;
import java.util.LinkedHashSet;
import java .util.Iterator;
/**
* @author R4R
*
*/
public class RemoveElements {
/**
* @param args
*/
public static void main(String[] args) {
LinkedHashSet Lhst = new LinkedHashSet();
Lhst.add("10");
Lhst.add("11");
Lhst.add("12");
Lhst.add("13");
Lhst.add("14");
Lhst.add("15");
Lhst.add("16");
System.out.println(" The LinkedHashSet contains the elements :"+Lhst);
Object obj=Lhst.remove("13");
System.out.println("The element from the LinkedHashSet is removed:"+obj);
System.out.println("Now the remaining elements in the LinkedHashSet are :" + Lhst);
// TODO Auto-generated method stub
}
}
The LinkedHashSet contains the elements :[10, 11, 12, 13, 14, 15, 16]
The element from the LinkedHashSet is removed:true
Now the remaining elements in the LinkedHashSet are :[10, 11, 12, 14, 15, 16]
Previous | Home | Next |