Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector vs ArrayList

 
Nicky narayan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What is the main difference b/w ArrayList and Vector?

As of my knowledge- Vector is Synchronized and ArrayList is not Synchronized.

But, we can synchronize the AyyaList by using Collections.synchronizeList(ArrayList).

then what is the main difference in between these two ?
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vector is a legacy class that is from Java 1.0 where as ArrayList introduce in Java 1.2 with the Collection Framework. The reason why Vector still exist because removing the class would result in break the client programmer’s code. You should not use Vector in new code. If you need a synchronized collection then you can use the method as you have already specified .
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Muhammad says, just use ArrayList. Asking what is the "main difference" between two things is almost always pointless.

Not to mention that using a class just because it is "synchronized" is likely to lead you into problems when you assume that the word "synchronized" means more than it actually does. So yes, use ArrayList and also study more about synchronization.
 
Nicky narayan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic