Vector 和 HashTable
来源:互联网 发布:角色数据读取失败 编辑:程序博客网 时间:2024/06/07 06:04
其实Vector 和 HashTable现在已经很少使用了,他们是同属于一个时代的,一般我们使用ArrayList 和HashMap 而且建议使用这两个,他们两个是一个时代的。
Vector
Vector 和ArrayList的区别: Vector是线程同步的,而ArrayList不是线程同步的,其他方面的实现两个基本一样,从下面的代码可以看到,它的底层实现也是数组。
protected Object[] elementData;
vector的扩容方式:默认的扩容的大小是变为原来的二倍,如果自己定义了它增加的个数,它会按照我们要求的增长个数进行增长
// 容量的增长模式 private void grow(int minCapacity) { // overflow-conscious code int oldCapacity = elementData.length; // 如果capacityIncrement>0,则每次容量增加capacityIncrement, 如果不是则容量增加 一倍 oldCapacity int newCapacity = oldCapacity + ((capacityIncrement > 0) ? capacityIncrement : oldCapacity); if (newCapacity - minCapacity < 0) newCapacity = minCapacity; if (newCapacity - MAX_ARRAY_SIZE > 0) newCapacity = hugeCapacity(minCapacity); elementData = Arrays.copyOf(elementData, newCapacity); }
那么capacityIncrement这个函数是什么含义呢?这是是Vector定义的数组自增大小,而且提供了一个构造函数,我们可以自己设置它增长的大小。
public Vector(int initialCapacity, int capacityIncrement) { super(); if (initialCapacity < 0) throw new IllegalArgumentException("Illegal Capacity: "+ initialCapacity); this.elementData = new Object[initialCapacity]; this.capacityIncrement = capacityIncrement; }
HashTable
HashMap 类与 Hashtable 大致相同,
但是Hashtable是同步的,HashMap是不同步的,
Hashtable不允许使用 null 键,HashMap允许使用 null 键,
Properties 是Hashtable的一个子类,属性类,经常被使用在配置文件中
getProperties(String key),一般读取文件的时候,都是获取字符串
获取系统的环境变量:
System.getProperties获取系统的环境变量
0 0
- vector和Hashtable
- Vector 和 HashTable
- Vector和Hashtable的使用:
- Vector、ArrayList和hashtable hashmap
- HashTable和HashMap; Vector和 ArrayList
- ArrayList 和Vector HashTable和HashMap
- Vector、ArrayList和hashtable hashmap的异同
- [转]Vector、ArrayList和hashtable hashmap数据结构
- 数据结构Vector和Hashtable的用法
- 分析Vector、ArrayList和hashtable hashmap数据结构
- Vector、ArrayList和Hashtable、HashMap数据结构
- Vector、ArrayList和hashtable、hashmap的异同
- ArrayList与Vector和HashMap与Hashtable
- Java记录 -72- Vector,HashTable和Properties
- List和ArrayList和Vector和HashTable和HashMap
- List和ArrayList和Vector和HashTable和HashMap区别
- Vector和ArrayList Hashtable和HashMap ArrayList和LinkedList
- Vector和arratList的区别 HashMap和Hashtable的区别
- UINavigationController笔记
- activiti工作流的web流程设计器整合视频教程 SSM和独立部署
- poi解析word文档(解析表格,emf,wmf,svg转jpg图片)
- 文章标题
- 返回最长上升子序列
- Vector 和 HashTable
- Android textAppearance的属性设置及TextView属性详解
- 编码习惯,优化直觉
- centos 6.7 (UDEV,、etc/hosts)安装 RAC 11.2.0.4 报错处理
- NetSdkDe2.0 右键弹出cmenu菜单类
- java 现成网站源码 SSM 框架 freemaker静态引擎
- android studio 一些有用的命令行
- 迭代器与NULL值的比较
- Java知识点练习小结(四)