Difference Between Arraylist And Vector : Core Java Interview Collection Question
Difference between Vector and Arraylist is the most common Core Java Interview question you will come across in Collection . This question is mostly used as a start up question by the Interviewers before testing deep roots of the Collection .
Vector , ArrayList classes are implemented using dynamically resizable array providing fast random access and fast list traversal very much like using an ordinary array . ArrayList support dynamic arrays that can grow as needed that is ArrayList can be dynamically increased or decreased in size .
Read Also : Difference between HashMap and ConcurrentHashMap
Arraylist vs Vector in Java
1. Synchronization and Thread-Safe
Vector is synchronized while ArrayList is not synchronized . Synchronization and thread safe means at a time only one thread can access the code .In Vector class all the methods are synchronized .Thats why the Vector object is already synchronized when it is created .
2. Performance
Vector is slow as it is thread safe . In comparison ArrayList is fast as it is non synchronized . Thus in ArrayList two or more threads can access the code at the same time , while Vector is limited to one thread at a time.
3. Automatic Increase in Capacity
A Vector defaults to doubling size of its array . While when you insert an element into the ArrayList , it increases
its Array size by 50% .
By default ArrayList size is 10 . It checks whether it reaches the last element then it will create the new array ,copy the new data of last array to new array ,then old array is garbage collected by the Java Virtual Machine (JVM) .
4. Set Increment Size
ArrayList does not define the increment size . Vector defines the increment size .
You can find the following method in Vector Class
public synchronized void setSize(int i) { //some code }
There is no setSize() method or any other method in ArrayList which can manually set the increment size.
5. Enumerator
Other than Hashtable ,Vector is the only other class which uses both Enumeration and Iterator .While ArrayList can only use Iterator for traversing an ArrayList .
6. Introduction in Java
java.util.Vector class was there in java since the very first version of the java development kit (jdk).
java.util.ArrayList was introduced in java version 1.2 , as part of Java Collections framework . In java version 1.2 , Vector class has been refactored to implement the List Inteface .
Please do mention in the comments in case if you have any doubts or suggestions regarding the post.
Difference Between Arraylist And Vector : Core Java Interview Collection Question的更多相关文章
- Top 25 Most Frequently Asked Interview Core Java Interview Questions And Answers
We are sharing 25 java interview questions , these questions are frequently asked by the recruiters. ...
- Core Java Interview Question Answer
This is a new series of sharing core Java interview question and answer on Finance domain and mostly ...
- Java中List,ArrayList、Vector,map,HashTable,HashMap区别用法
Java中List,ArrayList.Vector,map,HashTable,HashMap区别用法 标签: vectorhashmaplistjavaiteratorinteger ArrayL ...
- Java——(五)Collection之List集合、ArrayList和Vector实现类
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 一.List集合 List集合代表一个元素有序.客重复的集合,集合中每个元素都有其对应的顺序索引 ...
- Java ArrayList、Vector和LinkedList等的差别与用法(转)
Java ArrayList.Vector和LinkedList等的差别与用法(转) ArrayList 和Vector是采取数组体式格式存储数据,此数组元素数大于实际存储的数据以便增长和插入元素,都 ...
- Java集合框架(三)—— List、ArrayList、Vector、Stack
List接口 List集合代表一个有序集合,集合中每一个元素都有其对应的顺序索引.List集合容许使用重复元素,可以通过索引来访问指定位置的集合对象. ArrayList和Vector实现类 Arra ...
- Java容器类List、ArrayList、Vector及map、HashTable、HashMap的区别与用法
Java容器类List.ArrayList.Vector及map.HashTable.HashMap的区别与用法 ArrayList 和Vector是采用数组方式存储数据,此数组元素数大于实际存储的数 ...
- 【Java面试题】32 ArrayList和Vector的区别
1. Vector & ArrayList 相同点: 1.ArrayList和Vector都是继承了相同的父类和实现了相同的接口 2.底层都是数组实现的 3.初始默认长度都为10. 不同点: ...
- Java集合(2)——深入理解ArrayList、Vector和LinkedList
回顾 Java集合主要分为两个体系结构,Collection和Map.这篇博客主要介绍Collection子接口List下的三个经常使用的实现类:ArrayList.Vector和LinkedList ...
随机推荐
- redis实战笔记(3)-第3章 Redis命令
第3章 Redis命令 本章主要内容 字符串命令. 列表命令和集合命令 散列命令和有序集合命令 发布命令与订阅命令 其他命令 在每个不同的数据类型的章节里, 展示的都是该数据类型所独有的. 最 ...
- 做网站,乱码?应该选用什么编码?GB2312 ? UTF-8 ?
当然了,最常用的编码也就是GB2312 和 UTF-8 了. ================================================起==================== ...
- 微信小程序动态生成保存二维码
起源:最近小程序需要涉及到一些推广方面的功能,所以要写一个动态生成二维码用户进行下载分享,写完之后受益良多,特此来分享一下: 一.微信小程序动态生成保存二维码 wxml: <view class ...
- CocoaPods管理第三方
之前听伟哥说用CocoaPods做第三方库的管理很方便,今天看了下自己做了下感觉确实不错.下面开始,Let's go!! 1.安装CocoaPods之前,先确保本地有Ruby环境,因为CocoaPod ...
- 一个实用的却被忽略的命名空间:Microsoft.VisualBasic
当你看到这个命名空间的时候,别因为是VB的东西就匆忙关掉网页,那将会是您的损失,此命名空间中的资源最初目的是为了简化VB.NET开发而创建的,所以Microsoft.VisualBasic并不属于Sy ...
- 结合after使用content
结合after或before伪类,在元素的开头或结尾附加上一定的内容,content:""的引号中即是添加的内容,比如说我们这么写: <div>学而时习之不亦说乎< ...
- 在SQLSERVER中如何检测一个字符串中是否包含另一个字符串
--当charindex返回值大于0时则包含 为0不包含 select CHARINDEX('456','123456') SQL语句使用CHARINDEX函数,来测试一个字符串中是否包含另一个字 ...
- ModelState.IsValid always returning true while mocking a request
ASB.net MVC 视图验证里有一个IValidatableObject接口.这里面有一个验证方法.通常我们表单提交的时候dto就是用一个实现IValidatableObject这个接口的实体. ...
- 关于在web端运行项目,eclipse报PermGen space错误
之前在网上也查到过许多解决的方法,但可能因为本人脸黑........也修改过eclipse文件目录中的相关配置文件,并没有得到相应的帮助,因此把自己的改正方法分享下: window-->pref ...
- scala 编程思想—学习笔记
方法 方法是打包在某个名字下的小程序.在使用方法时,也就是调用方法时就会执行 这个小程序.方法将一组活动组合起来并赋予一个名字,这就是组织程序的最基本方式. scala 中方法的基本形式为 def m ...