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.
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.
They are obsolete, but they are not deprecated.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With