0
点赞
收藏
分享

微信扫一扫

【Java】如何清空Map

Hyggelook 2022-04-29 阅读 52
java后端

在开发中在使用Map时,如果需要将Map作为临时的数据存储和处理,可以不用每次都去新建一个Map,可以使用clear方法来进行清空Map。
例如:

Map<String, Object> map = new HashMap<>();
map.put("text", "hello");
System.out.print(map);
// Clear map
map.clear();
System.out.print(map)

两次的输出结果是:

{"text": "hello"}
{}
举报

相关推荐

0 条评论