本文鏈接: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"} {}