Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vector is an obsolete Collection

The Inspection reports any uses of java.util.Vector or java.util.hashtable. While still supported, these classes were made obsolete by the JDK 1.2 Collection classes and should probably not be used in new Development....

I have a project in Java which uses vector Everywhere, and I'm using JDK 8 which is the latest one. I want to know if I can run that application on latest java.

And tell if i can use some other keyword for ArrayList like Vector for new java.

like image 682
DeWy Sady Avatar asked May 16 '15 12:05

DeWy Sady


People also ask

Are vectors obsolete?

If a thread-safe implementation of List interface is required, we can either use CopyOnWriteArrayList class, which is a thread-safe variant of the ArrayList or synchronize ArrayList externally using the synchronizedList() method of the Collections class. That's all about why the Vector class is obsolete in Java.

Is Vector deprecated in Java?

They are obsolete, but they are not deprecated.

Is Vector a collection?

Vector is like the dynamic array which can grow or shrink its size. Unlike array, we can store n-number of elements in it as there is no size limit. It is a part of Java Collection framework since Java 1.2. It is found in the java.


1 Answers

First of all, although Vector is mostly obsoleted by ArrayList, it is still perfectly legal to use, and your project should run just fine.

As noted, however, it is not recommended to use. The main reason for this is that all of its methods are synchronized, which is usually useless and could considerably slow down your application. Any local variable that's not shared outside the scope of the method can safely be replaced with an ArrayList. Method arguments, return values and data members should be inspected closely before being replaced with ArrayList, lest you unwittingly change the synchronization semantics and introduce a hard-to-discover bug.

like image 144
Mureinik Avatar answered Oct 11 '22 15:10

Mureinik