点击运行
import java.util.HashMap; public class Main { public static void main(String[] args) { HashMap
sites = new HashMap<>(); // 检查该 HashMap 是否含有元素 boolean result = sites.isEmpty(); // true System.out.println("是否为空? " + result); // 往 HashMap 添加一些元素 sites.put(1, "Google"); sites.put(2, "Jiyik"); sites.put(3, "Taobao"); System.out.println("HashMap: " + sites); result = sites.isEmpty(); // true System.out.println("是否为空? " + result); } }
运行结果 :
正在执行...