Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Convert Vector to ArrayList in Java
Next article icon

Convert Vector to ArrayList in Java

Last Updated : 08 Sep, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

There are multiple ways to convert vector to ArrayList, using passing the Vector in ArrayList constructor and by using simple vector traversal and adding values to ArrayList.

Approach 1:

  1. Create a Vector.
  2. Add some values in Vector.
  3. Create a new ArrayList.
  4. Traverse vector from the left side to the right side.
  5. Start adding each element in ArrayList.

Below is the implementation of the above approach:

Java
// Convert Vector to ArrayList in Java import java.util.Vector; import java.util.ArrayList;  public class GFG {      public static void main(String[] args)     {          // Create a Vector that contain strings          Vector<String> v = new Vector<String>();          // add values in vector          v.add("a");         v.add("b");         v.add("c");         v.add("d");         v.add("e");          // Display the Vector          System.out.println(" Vector :  " + v);          ArrayList<String> Arrlist = new ArrayList<String>();          // Convert Vector to ArrayList         for (int i = 0; i < v.size(); i++)             Arrlist.add(v.get(i));         // Display ArrayList         System.out.println("\n ArrayList : " + Arrlist);     } } 

Time Complexity: O(n)

Approach 2:

  • Create a Vector.
  • Add some values in Vector.
  • Create an ArrayList and pass the Vector in ArrayList Constructor.

Syntax:

ArrayList<String> ArrList = new ArrayList<String>(vector);

Below is the implementation of the above approach:

Java
// Convert Vector to ArrayList in Java import java.util.Vector; import java.util.ArrayList;  public class GFG {      public static void main(String[] args)     {          // Create a Vector that contain strings          Vector<String> v = new Vector<String>();          // add values in vector          v.add("a");         v.add("b");         v.add("c");         v.add("d");         v.add("e");          // Display the Vector          System.out.println(" Vector :  " + v);          // Convert Vector to ArrayList         ArrayList<String> Arrlist             = new ArrayList<String>(v);          // Display ArrayList         System.out.println("\n ArrayList : " + Arrlist);     } } 

Output
 Vector :  [a, b, c, d, e]   ArrayList : [a, b, c, d, e]

Time Complexity: O(n)

Approach 3 : Using addAll()

  1. Declare and Initialize the Vector object with values.
  2. Now, declare the ArrayList.
  3. By using addAll() method, we can simply add all elements from Vector to ArrayList. Declare the vector object in the addAll() method i.e ArrayList_object.addAll(Vector_object).
  4. Print the ArrayList.
Java
// Java Program to Convert Vector to ArrayList  import java.util.ArrayList; import java.util.Vector;  public class GFG {      public static void main(String[] args)     {         // Create a Vector that contain strings         Vector<String> v = new Vector<String>();          // add values in vector          v.add("a");         v.add("b");         v.add("c");         v.add("d");         v.add("e");          // Display the Vector         System.out.println(" Vector :  " + v);          // Converting vector to ArrayList         ArrayList<String> Arrlist = new ArrayList<String>();         Arrlist.addAll(v);          // Displaying the above ArrayList         System.out.println("\n ArrayList : " + Arrlist);     } } 

Output
 Vector :  [a, b, c, d, e]   ArrayList : [a, b, c, d, e] 

Next Article
Convert Vector to ArrayList in Java

M

mukulsomukesh
Improve
Article Tags :
  • Java
  • Technical Scripter
  • Technical Scripter 2020
  • Java-Collections
  • Java-ArrayList
  • Java-Vector
Practice Tags :
  • Java
  • Java-Collections

Similar Reads

    How to Convert Vector to Array in Java?
    As we all know an array is a group of liked-typed variables that are referred to by a common name while on the other hand vectors basically fall in legacy classes but now it is fully compatible with collections. It is found in java.util package and implement the List interface which gives a superior
    3 min read
    Convert List to Array in Java
    The List interface provides a way to store the ordered collection. It is a child interface of Collection. It is an ordered collection of objects where duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. Now here we are give
    5 min read
    How to Convert HashMap to ArrayList in Java?
    In Java a HashMap is a collection that stores key-value pairs on the other hand, an ArrayList is a collection that stores dynamic arrays. There are some scenarios where we need to convert a HashMap into an ArrayList such as:Extracting only the keys or values in the list form.Converting key-value pai
    2 min read
    Conversion of Array To ArrayList in Java
    Following methods can be used for converting Array To ArrayList: Method 1: Using Arrays.asList() method Syntax: public static List asList(T... a) // Returns a fixed-size List as of size of given array. // Element Type of List is of same as type of array element type. // It returns an List containing
    5 min read
    Iterating over ArrayLists in Java
    ArrayList is a part of collection framework and is present in java.util package. It provides us with dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. This class is found in java.util package. With
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences