Tuesday 2 June 2015

How to check LinkedHashSet Empty Or not

package com.javapro.vector.linkedhashset;

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

public class IsEmpty {
   
    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("lhs is = "+lhs);
       
        //Returns true if this set contains no elements.
       
        System.out.println(lhs.isEmpty());
       
        Set<String> lhs2 = new LinkedHashSet<String>();
       
        //Returns true if this set contains no elements.
        System.out.println(lhs2.isEmpty());
    }

}


Output:

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

false

true
 

No comments:

Post a Comment