Mario S
Mario S

Reputation: 1984

Methods in Java API for Lotus Notes returns Vector and not ArrayList

If I need to retrieve the value of a field, I will need to use this function

public java.util.Vector getItemValue(String name) throws NotesException

Well, this method like any others in the Lotus Notes Java API returns Vector objects. In this answer is explained that Vector is obsolete. But this answer on the same question make me think that the using of Vector maybe was necessary.

Although Enumerations are faster, they don't check if the collection was modified during iteration, which can cause issues, and given that Vector might be chosen for its syncronization - with the attendant access from multiple threads, this makes it a particularly pernicious problem.

When we use the Lotus Notes Java API, is there any problem if we convert the resulting Vector objects to ArrayList objects?

Vector<String> vector = (Vector<String>) doc.getItemValue("somefield");
ArrayList<String> list = new ArrayList<String>(vector);

Or, in general, isn't this conversion recommended?

EDIT: Just in case, I don't want/need to use Vector objects, but the methods from the Lotus Notes Java API always return that. So, I have two options: (1) always convert the Vector objects to ArrayList or any other better option, or (2) just use Vector objects.

In short, my doubt is: is it safe to convert Vector objects to ArrayList in situations like this?

Upvotes: 2

Views: 891

Answers (3)

Mureinik
Mureinik

Reputation: 311308

Vectors have been deprecated for ages. Unless you particularly need it's thread safety, just use an ArrayList - it'll be faster. And even if you do require your collection to be thread safe, there are better choices in modern JDKs, such as the CopyOnWriteArrayList.

Upvotes: 0

Christian Kuetbach
Christian Kuetbach

Reputation: 16060

You can convert the Vector into a more modern Collection. But You have to ensure, that you don't use Java 7 Features or classes.

As far as I know, IBM Notes still uses an IBM Java 6 VM.

And generics are a litte dangerous, because I am not sure, that every Item, which is returned by getItemValue() in the Vector is a String.

Update

I would prefer, to use the Vector because thats the way, the API works.

In fact the IBM Notes / Domino API is some kind of horrible. There is a wrapper for the API from openNTF.

Upvotes: 1

chiastic-security
chiastic-security

Reputation: 20520

Don't use deprecated Vectors. They're notoriously slow.

If you need a synchronised list, you can turn any list into a synchronised version with

syncList = Collections.synchronizedList(list);

Upvotes: 1

Related Questions