BACK
The method public boolean remove(Object o) removes the particular element from the linkedhashset,if the element is present.Also,returns true if the element is present,Otherwise returns false.
Example Program
import java.util.LinkedHashSet; public class LinkedHashSetRemove { public static void main(String[] args) { LinkedHashSet<String> lh = new LinkedHashSet<String>(); lh.add("Add"); lh.add("Sub"); lh.add("Mul"); lh.add("Div"); lh.add("Expo"); System.out.println("Size of set is: " + lh.size()); for (String value : lh) { System.out.println("Value = " + value); } lh.remove("Div"); System.out.println("Now size of set is: " + lh.size()); for (String value : lh) { System.out.println("Value = " + value); } } }
Output
Size of set is: 5
Value = Add
Value = Sub
Value = Mul
Value = Div
Value = Expo
Now size of set is: 4
Value = Add
Value = Sub
Value = Mul
Value = Expo