Java 中清空map

本文链接:https://blog.csdn.net/TsuiXh/article/details/87879004
在开发中在使用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"}
{}

  

原文地址:https://www.cnblogs.com/Allen-rg/p/11364313.html