博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Difference Between Arraylist And Vector : Core Java Interview Collection Question
阅读量:6691 次
发布时间:2019-06-25

本文共 2468 字,大约阅读时间需要 8 分钟。

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 :     
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  .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. 

转载于:https://www.cnblogs.com/kungfupanda/p/6736721.html

你可能感兴趣的文章
练习:输出整数每一位,计算算数,9出现次数,输出图案,水仙花数
查看>>
操作系统的发展
查看>>
HEVC码流简单分析
查看>>
搭建蚂蚁笔记(服务器)
查看>>
lnmp
查看>>
二分查找
查看>>
Cloud Test 在手,宕机时让您不再措手不及
查看>>
Centos7.2安装Vmware Tools
查看>>
深入理解Java内存模型(一)——基础
查看>>
美图秀秀下载|美图秀秀电脑版下
查看>>
生产者消费者模式
查看>>
tomcat的Context配置,虚拟访问数据
查看>>
ORACLE---添加控制文件
查看>>
Qt中QString,char,int,QByteArray之间到转换
查看>>
Exchange Server 2007邮箱存储服务器的集群和高可用性技术(上)
查看>>
磁盘管理与磁盘阵列RAID
查看>>
Linux学习笔记4-软件安装
查看>>
8.python之面相对象part.8(类装饰器)
查看>>
Spark通过Java Web提交任务
查看>>
Javascript动态加载脚本与样式
查看>>