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"}
{}

  

 

posted @ 2019-08-16 15:41  静悟生慧  阅读(15514)  评论(0编辑  收藏  举报