views:

57

answers:

3

Hi,

Which of the methods of java Vector class is synchronized.Since there is no explicit synchronized in javadoc.

+2  A: 

All methods of the Vector class that change the state of the vector are synchronized.

Steve Emmerson
Where it is documented?
JavaUser
http://www.docjar.com/docs/api/java/util/Vector.html. Scroll down to the method detail section.
Justin Ardini
Thx Justin..Nice
JavaUser
Beware: those are javadocs from the Apache Harmony implementation.
Stephen C
@Stephen No need to beware. The documentation from Sun says the class is synchronized. See <http://java.sun.com/javase/6/docs/api/index.html> for example.
Steve Emmerson
@Steve - you miss my point. It is **bad idea** to use the Apache javadocs to tell you about the Sun APIs ... or vice versa.
Stephen C
+1  A: 

The explanation is in the last line of the class Javadoc:

Unlike the new collection implementations, Vector is synchronized.

Vector is essentially a synchronized ArrayList

Michael Mrozek
A: 

In the absence of explicit statements in the Javadoc, look at the source code. For instance, you can find them in the src.zip file in your JDK installation.

In fact, nearly all methods that access or update the state of the Vector synchronize at some point. However, the Iterator returned by iterator() and the Enumeration returned by elements() only synchronize during next / hasNext calls.

Stephen C