Map.clear() vs new Map : Which one will be better? Map.clear()与new Map:哪个更好?
- 论坛
- Map.clear() vs new Map : Which one will be better? Map.clear()与new Map:哪个更好?
8 浏览
Map.clear() vs new Map : Which one will be better? Map.clear()与new Map:哪个更好?
我有一个语法为Map
的Map。
在这个Map中可能有1000个数据。
当我的应用程序需要获取新的数据列表时,我必须清除Map。但是当我看到Map.clear()方法的代码时,我意识到clear方法会循环n次(其中n是Map中的数据数量)。所以我想重新定义Map为testMap = new HashMap
,之前使用的Map将会被垃圾回收。
但我不确定这是否是一个好的方式。我正在开发移动应用程序。
你能指导我吗?