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

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM