How to check HashSet Empty Or not

import java.util.HashSet;
import java.util.Set;

public class IsEmpty {

public static void main(String[] args) {

Set<String> hs = new HashSet<String>();
hs.add(“java”);
hs.add(“php”);
hs.add(“html”);
hs.add(“javascript”);
hs.add(“mysql”);

//print hashset
System.out.println(“hashset = “+hs);

System.out.println(hs.isEmpty());

HashSet<String> hs2 = new HashSet<String>();

System.out.println(hs2.isEmpty());
}

}

Output:

hashset = [javascript, php, html, java, mysql]

false

true

Leave a Reply

Your email address will not be published. Required fields are marked *

− 7 = 3