Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added an ArrayList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.
An application can increase the capacity of an ArrayList instance before adding a large number of elements using the ensureCapacity operation. This may reduce the amount of incremental reallocation.
这里说到ArrayList的一个容量的问题,如果想要Add数量比较多的元素,最好要使用该类
的一个叫做ensureCapacity的方法来确保ArrayList实例具有你所要指定的一个最小的容量。这样的话,对于大容量ArrayList实例,应该就可以由JDK正确地指定到内存中了,这些内存段是否连续,当然是由JDK来处理的问题了。至于这个最小的容量可以达到多少,这里没有讲明,不过应该是和内存多少和每个元素的大小有关系的吧,不好一概而论!
防止out of memory,有一个方法,就是根据每次调用add方法的时候add的返回值(boolean型)来判断!
至于hashTable,与容量有关的是一下的一段:
The initial capacity controls a tradeoff between wasted space and the need for rehash operations, which are time-consuming. No rehash operations will ever occur if the initial capacity is greater than the maximum number of entries the Hashtable will contain divided by its load factor. However, setting the initial capacity too high can waste space.
这里提到初始容量和rehash方法,也就是hashtable在初始容量不够用的情况下可以通过
rehash方法自动增加容量,至于可以增加多少,文档也没有提,显然也是类似于ArrayList的吧。
发表评论
-
报表导出参数
2013-02-27 16:49 1257JRExporterParameter. JASPER_PR ... -
report
2013-02-22 12:08 703http://blog.csdn.net/usedtolov ... -
gwt
2013-02-21 17:02 869Google Web Toolkit的缩写,有了 GWT可以使 ... -
线程安全Collections.synchronizedList
2013-01-23 22:30 46631Collections.synchronizedList引发 ... -
java 一些么曾用的领域
2013-01-23 21:48 763阻塞与非阻塞io 1、nio 1.4 + 2、aio ... -
json 包依赖
2013-01-23 18:02 885commons-beanutils.jar commons ... -
线程池
2013-01-22 22:20 01、Executors类里面提供了一些静态工厂,生成一些常用 ... -
struts2 ext fileUpload
2012-11-23 16:19 0觉得这篇还写的可以,http://www.cnblogs.co ... -
myeclipe jvm setting
2012-11-21 10:23 0原文出处: 由MyEclipse内 ... -
IP转化
2012-07-15 15:56 849IP相互转化 /* * >>>无符 ... -
weblogic下载
2012-04-22 14:07 0weblogic 10.0版本的下载路径: http://w ... -
xml处理
2012-04-07 17:48 0一、此段代码是struts2中struts.xml的解析的部分 ... -
配置文件
2012-04-07 12:32 0以前教材源码的配置文件,很久不用,免的无从下手 一、web. ... -
零碎零碎
2012-02-27 16:30 01、SimpleDateFormat 的使用: Simple ... -
synchronized使用
2011-08-03 23:38 881synchronized关键字的使用: ①是某个对 ... -
Java修饰符
2011-08-03 23:18 910①类修饰符: public 可以从其他类中访问 a ... -
JSP内置对象
2011-07-31 21:37 848以下对JSP内置对象及其方法做一概述 一、reques ... -
设计模式-单例 Singleton
2011-07-31 03:03 709一、构成单例模式要点: ①、只有一个实例 ②、私有的构造方 ... -
嵌套类 内部类 静态内部类 匿名内部类
2011-07-30 18:03 1119一、嵌套类(Nested Class)分为:内部类(Inner ... -
JDK_7 Download
2011-07-30 01:11 1351尝尝鲜 哈哈: Linux x86 - RPM Ins ...
相关推荐
Hashtable与ArrayList的简单应用
比较Vector、ArrayList和hashtable hashmap
经典讲解List和ArrayList和Vector和HashTable和HashMap区别
比较分析Vector、ArrayList和hashtable hashmap数据结构
Arraylist、Hashtable、Vector 动态数组分别介绍
c#数据结构之array,arraylist,hashtable,dictionary
arraylist Hashtable的使用,程序开发者可参考
C#中的集合示例(Array,ArrayList,Hashtable,List)
WinFormHashTable最简单用法,.net hashtable ,hashtable ,hashtable用法
HashTable源码
本文详细介绍了ArrayList、HashTable、List、Dictionary的用法,以及什么情况选用该数组,以便提高开发效率。希望对大家有所帮助
我们用的比较多的非泛型集合类主要有 ArrayList类 和 HashTable类。我们经常用HashTable 来存储将要写入到数据库或者返回的信息,在这之间要不断的进行类型的转化,增加了系统装箱和拆箱的负担,如果我们操纵的数据...
List、ArrayList、Vector及map、HashTable、HashMap分别的区别
List、ArrayList、Vector及map、HashTable、HashMap的区别与用法 使用容器排序 Vector由于使用了synchronized方法(线程安全)
自己写的json字符串转hashtable,或者把hashtable转为json字符
VS2008环境下C#编写的个人通讯录,有详细的注释。希望能和大家一起学习。
以下是对java中ArrayList与Vector的区别以及HashMap与Hashtable的区别进行了详细的解析。需要的朋友可以过来参考下
Java中List、ArrayList、Vector及map、HashTable、HashMap分别的区别.
主要介绍了C# ArrayList、HashSet、HashTable、List、Dictionary的区别的相关知识点内容,有需要朋友们参考下。