• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SoftwareTestingo - Jira Selenium Protractor Testing SDLC Agile Methodology

Java Selenium Tutorial & Testing Interview Questions

  • Home
  • Interview Questions
  • Java
  • Java Programs
  • Test Cases
  • Selenium
  • Manual Testing
  • Difference
  • Search
SoftwareTestingo » Difference » Difference Between ArrayList VS Vector In Java With Example

Difference Between ArrayList VS Vector In Java With Example

Last Updated on: April 24, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • ArrayList VS Vector
  • When to use ArrayList?
  • When to use Vector?

ArrayList VS Vector In Java: In this article, we will discuss the difference between ArrayList Vs Vector classes in detail. Lets us move on and discuss the key differences between these 2 List classes

Check This: Enumeration VS Iterator VS ListIterator in Java

ArrayList VS Vector

 ArrayList Vector
It is introduced in the original collection framework in Java 1.2 version It is a legacy class including Stack, Dictionary, HashTable & Properties and introduced in Java 1.0 version
ArrayList methods are non-synchronized All legacy collection classes are synchronized, thus Vector is synchronized
(i.e.; all methods are synchronized)
As ArrayList is non-synchronized, hence it isn’t thread-safe. So, the programmer needs to handle thread-safety while working in a multi-threaded environment As Vector is synchronized, hence it is thread-safe. So, no need to worry while working in a multi-threaded environment, as only one thread gets a chance to work at any given time
This is comparatively faster as it is non-synchronized, as threads don’t require to obtain the lock before operating on ArrayList Performance-wise it is slower compared with ArrayList due to synchronization, as threads need to wait for their chance to operate on a Vector object
ArrayList increases its size by 50% of a current array when its capacity exceeds It increases its size by 100% of a current array when its capacity exceeds
The only Iterator is allowed to iterate item/elements inside ArrayList Both Iterator & Enumeration can be used to iterate item/elements inside Vector
ArrayList can be converted into synchronized ArrayList using static utility methods of  Collections class collection.synchronizedList(ArrayList); No need to do that, as already it is synchronized by default

When to use ArrayList?

  • If performance is the factor while storing element/objects, then ArrayList is apt
  • But definitely, extra precautions need to be taken while working with a multiple-threaded environment
  • Also, check how much extra space is required when List is full; if 50% of original size if required then ArrayList will fit the case perfectly
Check Also: Dynamic Polymorphism

When to use Vector?

  • If we aren’t concerned with performance, but element/objects need to be accessed in a thread-safe manner, then the Vector is the good choice
  • But performance will be a big hit, as every thread to need to wait to obtain the lock before accessing vector element/objects
  • Here, size increase in 2 times the original size; so if there are the number of items to be added then Vector will fit the bill perfectly

Your comment/suggestions/feedback of ArrayList VS Vector will help a lot of people in the QA community for helping them in cracking the interviews.

    Filed Under: Difference

    Reader Interactions

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Tutorials Important Links

    • Software Testing Jobs
    • Manual Testing Tutorial
    • Selenium Tutorial
    • Core Java Tutorial
    • TestNG Tutorial
    • Java Programs
    • Selenium Programs
    • Manual Test Cases
    • Interview Tips
    • Contact US
    • www.softwaretestingo.com

    Important Links

    • Software Testing Interview Questions
    • Agile Interview Questions
    • Manual Testing Interview Questions
    • Testing Interview Questions
    • Selenium Interview Questions
    • Selenium Real Time Interview Questions
    • Selenium WebDriver Interview Questions
    • Automation Framework Interview Questions
    • Appium Interview Questions
    • TestNG Interview Questions
    • Java Interview Questions
    • Core Java Interview Questions

    Categories

    Copyright © 2021 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy