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

svarog
  • 469
  • 4
  • 13
  • 1
    Possible duplicate of [Keep a programming language backwards compatible vs. fixing its flaws](https://softwareengineering.stackexchange.com/questions/191858/keep-a-programming-language-backwards-compatible-vs-fixing-its-flaws) – gnat Jun 15 '17 at 12:16
  • are vectors "flawed" ? – svarog Jun 15 '17 at 12:19
  • 4
    Your question already has answers on Stack Overflow: [Why is Java Vector class considered obsolete or deprecated?](https://stackoverflow.com/q/1386275/1521179) – amon Jun 15 '17 at 12:28

1 Answers1

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());
Walfrat
  • 3,456
  • 13
  • 26