java hashmap频繁创建还是清空重复利用?
各位好,请教个问题, hashmap频繁创建还是清空重复利用合理? 这里hashmap中的数据大概会有100-200个元素,如果new的话大概需要创建20000个左右function(){h = null; //new hashmap
while(true){
if(condition)
break;
if(condition00){
h = new hashmap //hashmap clear
}
其余逻辑
}
} 很奇怪lz的需求,为什么会出现这种循环的new?这样很影响效率。
你直接new,然后根据需要,删除或是添加不就行了。
PS,循环的new,之前的会被gc掉。
页:
[1]