Tuesday 2 June 2015

How To Remove Element of LinkedHashset


import java.util.LinkedHashSet;
import java.util.Set;

public class RemoveElement {
   
    public static void main(String[] args) {
       
        Set<String> lhs = new LinkedHashSet<String>();
       
        lhs.add("mumbai");
        lhs.add("delhi");
        lhs.add("kolkata");
        lhs.add("chandigarh");
        lhs.add("dehradun");
      
        //print linkedhashset
        System.out.println("Before remove lhs is = "+lhs);

        //Removes the specified element
        //from this set if it is present

        lhs.remove("kolkata");
       
        System.out.println("After remove lhs is = "+lhs);
       
    }

}




Output:

Before remove lhs is = [mumbai, delhi, kolkata, chandigarh, dehradun]

After remove lhs is = [mumbai, delhi, chandigarh, dehradun]

No comments:

Post a Comment