在Java中,判断一个Map是否为空有多种方法。以下是其中一种常用的方法:
Map<String, String> map = new HashMap<>();
if (map.isEmpty()) {
System.out.println("Map is empty");
} else {
System.out.println("Map is not empty");
}
Map<String, String> map = new HashMap<>();
if (map.size() == 0) {
System.out.println("Map is empty");
} else {
System.out.println("Map is not empty");
}
这两种方法都可以用来判断Map是否为空,根据需要选择其中一种即可。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:map判断是否为空的方法是什么