5

I'm writing some code to do some SSH jobs on a remote machine and one of the methods I'm (forced of) using returns a Vector type. I've learned about them several years ago but never had the chance of actually using them until now.

What I do know about them is

  1. They are not thread safe
  2. They are very old and are deprecated (Netbeans warns me it's an "Obsolete Collection")

Not being thread-safe seems not that of a big of a deal if you're being careful about it. but I don't think it's enough to dismiss them. Am I missing something?

EDIT:

It seems I've touched a serious issue here with Vectors being obsolete(deprecated may not be the right word), what I want to know is why are vectors being so avoided in the first place

3

1 Answer 1

7

In Java8 Vector's source, there is no depracated notice.

There is the following comment in the header :

Unlike the new collection implementations, {@code Vector} is synchronized. If a thread-safe implementation is not needed, it is recommended to use {@link ArrayList} in place of {@code Vector}.

Fuerthermore you can use Collections.synchronisedList() with an ArrayList as parameter to replace what a vector is able to do.

But otherwise, no Vector works well.

If you really don't like it do :

List l = new ArrayList(myFunctionThatReturnAVector());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.