Difference between arraylist and vector
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   saran_s
Posted On:   Thursday, November 18, 2004 05:38 AM

Where can we use arraylist but not vector and viceversa?

Re: Difference between arraylist and vector

Posted By:   Vikas_Singh  
Posted On:   Tuesday, February 8, 2005 02:32 AM

plz tell me abt above question And also where can we use arraylist and where vector

Re: Difference between arraylist and vector

Posted By:   James_Watson  
Posted On:   Thursday, November 18, 2004 12:50 PM

The main difference between a Vector and an ArrayList is that ArrayList is not synchronized by default. This should tend to make ArrayList faster when synchronization id not needed.

The other differences are that ArrayList came later when the Collections interfaces were introduced while the Vector preceeded the Collection and List interfaces and was refactored to implement them. This means there are a lot of methods in Vector that are not part of the List interface. If you use these methods, it will make it more difficult to refactor your code should you want to switch to a different List.

Note that you can easily synchronize an ArrayList by passing it to the Collection.synchronizedList() method and using the returned wrapper as your list reference. I don't use Vector and I don't think it should be used unless absolutely neccesary. For example some Swing and AWT interfaces only take Vector (annoyingly.)
About | Sitemap | Contact