Vector vs ArrayList in Java Last Updated : 07 Dec, 2022 Comments Improve Suggest changes Like Article Like Report ArrayList and Vectors both implement the List interface, and both use (dynamically resizable) arrays for their internal data structure, much like using an ordinary array. Syntax: ArrayList: ArrayList<T> al = new ArrayList<T>(); Vector: Vector<T> v = new Vector<T>(); ArrayList Vs vector S. No. ArrayListVector1.ArrayList is not synchronized.Vector is synchronized.2.ArrayList increments 50% of the current array size if the number of elements exceeds ts capacity.Vector increments 100% means doubles the array size if the total number of elements exceeds its capacity.3.ArrayList is not a legacy class. It is introduced in JDK 1.2.Vector is a legacy class.4.ArrayList is fast because it is non-synchronized.Vector is slow because it is synchronized, i.e., in a multithreading environment, it holds the other threads in a runnable or non-runnable state until the current thread releases the lock of the object.5.ArrayList uses the Iterator interface to traverse the elements.A Vector can use the Iterator interface or Enumeration interface to traverse the elements.6ArrayList performance is high Vector performance is low 7Multiple threads is allowed only one threads are allowed . Significant Differences between ArrayList and Vector: Synchronization: Vector is synchronized, which means only one thread at a time can access the code, while ArrayList is not synchronized, which means multiple threads can work on ArrayList at the same time. For example, if one thread is performing an add operation, then there can be another thread performing a remove operation in a multithreading environment. If multiple threads access ArrayList concurrently, then we must synchronize the block of the code which modifies the list structurally or allow simple element modifications. Structural modification means the addition or deletion of element(s) from the list. Setting the value of an existing element is not a structural modification. Performance: ArrayList is faster. Since it is non-synchronized, while vector operations give slower performance since they are synchronized (thread-safe), if one thread works on a vector, it has acquired a lock on it, which forces any other thread wanting to work on it to have to wait until the lock is released.Data Growth: ArrayList and Vector both grow and shrink dynamically to maintain optimal use of storage - but the way they resize is different. ArrayList increments 50% of the current array size if the number of elements exceeds its capacity, while vector increments 100% - essentially doubling the current array size.Traversal: Vector can use both Enumeration and Iterator for traversing over vector elements, while ArrayList can only use Iterator for traversing.Applications: Most of the time, programmers prefer ArrayList over Vector because ArrayList can be synchronized explicitly using Collections.synchronizedList. How to get Synchronized version of arraylist object: by default arraylist is object is non-synchronized but we can get synchronized version of arraylist by using collection class Synchronized List() method. Java /*package whatever //do not write package name here */ import java.io.*; class GFG { public static void main (String[] args) { public static List SynchronizedList(list1) // non synchronized ArrayList l1 = new ArrayList(); // Synchronized List l= Collections.SynchronizedList(l1); } } Note: ArrayList is preferable when there is no specific requirement to use vector. Java // Java Program to illustrate use // of ArrayList and Vector in Java import java.io.*; import java.util.*; class GFG { public static void main (String[] args) { // creating an ArrayList ArrayList<String> al = new ArrayList<String>(); // adding object to arraylist al.add("Practice.GeeksforGeeks.org"); al.add("www.GeeksforGeeks.org"); al.add("code.GeeksforGeeks.org"); al.add("contribute.GeeksforGeeks.org"); // traversing elements using Iterator' System.out.println("ArrayList elements are:"); Iterator it = al.iterator(); while (it.hasNext()) System.out.println(it.next()); // creating Vector Vector<String> v = new Vector<String>(); v.addElement("Practice"); v.addElement("quiz"); v.addElement("code"); // traversing elements using Enumeration System.out.println("\nVector elements are:"); Enumeration e = v.elements(); while (e.hasMoreElements()) System.out.println(e.nextElement()); } } OutputArrayList elements are: Practice.GeeksforGeeks.org www.GeeksforGeeks.org code.GeeksforGeeks.org contribute.GeeksforGeeks.org Vector elements are: Practice quiz code How to choose between ArrayList and Vector? ArrayList is unsynchronized and not thread-safe, whereas Vectors are. Only one thread can call methods on a Vector, which is slightly overhead but helpful when safety is a concern. Therefore, in a single-threaded case, ArrayList is the obvious choice, but where multithreading is concerned, vectors are often preferable.If we don't know how much data we will have but know the rate at which it grows, Vector has an advantage since we can set the increment value in vectors.ArrayList is newer and faster. If we don't have any explicit requirements for using either of them, we use ArrayList over vector. Comment More infoAdvertise with us Next Article Vector vs ArrayList in Java N Nitsdheerendra Improve Article Tags : Java Java-Collections Java-ArrayList java-list Java-List-Programs +1 More Practice Tags : JavaJava-Collections Similar Reads Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s 10 min read Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per 15+ min read Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it, 13 min read Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me 15+ min read Collections in Java Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac 15+ min read Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an 13 min read Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt 10 min read Java Programs - Java Programming Examples In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its 8 min read Java Interface An Interface in Java programming language is defined as an abstract type used to specify the behaviour of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains static constants and abstract methods. Key Properties of Interface:The interface in Java is a mechanism to 12 min read Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca 7 min read Like