集合容量的获取
来源:互联网 发布:自动记录足迹软件 编辑:程序博客网 时间:2024/06/04 18:40
If you know in advance what the size of the ArrayList
is going to be, it is more efficient to specify the initial capacity. If you don't do this, the internal array will have to be repeatedly reallocated as the list grows.
An ArrayList
object has a capacity and a size.
- The capacity is the total number of cells.
- The size is the number of cells that have data in them.
- Cells 0 up through size-1 have data in them.
- Data are added in order. Before cell N gets data, cells 0, 1, 2, ... N-1 must hold data.
The size increases by one each time an element is added. However, the capacity remains unchanged until the ArrayList
is full. When an element is added to a full list, the Java runtime system will greatly increase the capacity of the list so that many more elements can be added.
To find out the current size of an ArrayList
use its size()
method.
import java.lang.reflect.Field;import java.util.ArrayList;public class Test { public static void main(String[] args) throws Exception { ArrayList<Integer> list = new ArrayList<Integer>(3); for (int i = 0; i < 17; i++) { list.add(i); System.out.format("Size: %2d, Capacity: %2d%n", list.size(), getCapacity(list)); } } static int getCapacity(ArrayList<?> l) throws Exception { Field dataField = ArrayList.class.getDeclaredField("elementData"); dataField.setAccessible(true); return ((Object[]) dataField.get(l)).length; }}
0 0
- 集合容量的获取
- 获取硬盘的容量
- 获取SD卡的容量
- 关于SD卡总容量和可用容量的获取
- android获取SD卡的总容量,已使用的容量,剩余容量
- 获取SD卡的剩余容量
- 获取SD卡的剩余容量
- Android_02_获取SD卡的可用容量
- Android中sdcard容量的获取
- 9.获取外部存储卡的容量
- android基础--获取sdcard的总容量
- ArrayList集合容量增长
- 常用集合的默认初始容量和扩容的原因
- 集合的默认初始容量、加载因子、扩容增量
- 集合的默认初始容量、加载因子、扩容增量
- 获取SIM/UIM卡的联系人容量及已用容量信息
- mac下根据文件路径,获取该文件所在磁盘的总容量和剩余容量
- iOS开发 - 如何获取设备的总容量和可用容量
- 如何申请一个新的repo
- 前端
- ios 嵌套 H5 页面 一像素底部边框不出现
- 遥测地面站 资料收集
- ORA-12518: TNS:listener could not hand off client connection .
- 集合容量的获取
- Error configuring application listener of class org.springframework.web.context.ContextLoaderListene
- 卡牌游戏(queue的基础应用)
- linux命令详解之rpm命令参数使用方法
- SGU 110 Dungeon(计算几何)
- __weak 与__strong的理解与应用
- RPC在neutron中的应用
- Mysql存储过程使用多个游标的处理
- 如何将centos7中的网卡名字改为eth格式