Tuesday 2 June 2015

How to remove all element from LinkedHashSet

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

public class RemoveAll {
   
    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 clear lhs is = "+lhs);
  
        //Removes all of the elements from this set
        lhs.clear();
       
        System.out.println("After clear lhs is = "+lhs);
       
    }

}

Output:

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

After clear lhs is = []


No comments:

Post a Comment