HashSet isEnpty để kiểm tra HashSet có chứa phần tử nào hay không. Trả về true nếu HashSet rỗng.
Syntax
public boolean isEmpty()
Ví dụ
import java.util.HashSet; public class Main { public static void main(String[] args) { HashSet<String> h = new HashSet<>(); System.out.println("String is empty: " + h.isEmpty()); h.add("zzz"); System.out.println("String is empty: " + h.isEmpty()); } }
Output:
String is empty: true
String is empty: false