当使用putAll而不是put时,我看到巨大的性能优势。 请参见下面的示例程序:
公共类SampleTest {
public static void main(final String[] args) {
final Map testMap = new HashMap<>();
final Map testMap2 = new HashMap<>();
final LocalDateTime startTestTime = LocalDateTime.now();
for(int i=0; i < 1000000; i++) {
testMap.put(i+"", i+"");
}
final LocalDateTime endTestTime = LocalDateTime.now();
System.out.println("<<<<<<<<>>>>>>>>>>");
System.out.println(ChronoUnit.MILLIS.between(startTestTime, endTestTime));
final LocalDateTime startTestTime1 = LocalDateTime.now();
testMap2.putAll(testMap);
final LocalDateTime endTestTime1 = LocalDateTime.now();
System.out.println("<<<<<<
最后
以上就是怕黑八宝粥最近收集整理的关于map集合的putall_Map.put和Map.putAll方法之间的区别?的全部内容,更多相关map集合内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复