在Java中6SE ArrayList的增长策略 [英] Growth Policy of ArrayList in Java 6SE

查看:166
本文介绍了在Java中6SE ArrayList的增长策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有人知道ArrayList的用Java 1.6增长的政策? java的医生说。

I was wondering if anyone knows the growth policy of ArrayList in Java 1.6? The java doc says

生长策略的细节没有指定之外的事实,增加一个元件具有恒定摊销时间成本。

The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.

但我只是想知道的细节,因为我知道我瞄准,启动大小,但我要确保我正在做的初始大小不够大,不会造成即时调整大小。我知道跟HashMap中你可以设置一个负载系数是有什么类似的事情发生在回地面?或者是当空间出来,它总是不断增加?

But I just wonder the details because I know the size I'm targeting to start but I want to make sure I'm making the initial size big enough to not cause an instant resize. I know with HashMap you can set a load factor is there something similar happening in the back ground? Or is it always growing when space is out?

推荐答案

ArrayList中不需要loadFactor因为它总是生长在它是100%充满,这样你就可以准确的大小创建它,你事先知道它如果您填写的许多元素在以后不会增长。另一方面散列表变得越来越低效就越被填充,从而可以ajust性能之间的tradoff并与loadFactor浪费空间,但是这不是对可增长阵列如ArrayList的情况

ArrayList doesn't need a loadFactor as it always grows when it is 100% filled, so you can create it with exactly the size you know in advance and it won't grow if you fill that many elements in later. Hashtables on the other hand become ever more inefficient the more they are filled, and thus you can ajust the tradoff between performance and wasted space with the loadFactor, but this isn't the case for growable Arrays like ArrayList.

这篇关于在Java中6SE ArrayList的增长策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆