What are the differences between ArrayList and Vector?
ArrayList and Vector both implements List interface and maintains insertion order.But there are many differences between ArrayList and Vector classes...ArrayListis not synchronized.ArrayListincrements 50% of current array size if number of element exceeds from its capacity.ArrayListis not a legacy class, it is introduced in JDK 1.2.ArrayListis fast because it is non-synchronized.ArrayListuses Iterator interface to traverse the elements.
Vector -
Vectoris synchronized.Vectorincrements 100% means doubles the array size if total number of element exceeds than its capacity.Vectoris a legacy class.Vectoris slow because it is synchronized i.e. in multithreading environment, it will hold the other threads in runnable or non-runnable state until current thread releases the lock of object.Vectoruses Enumeration interface to traverse the elements. But it can use Iterator also.
Yorumlar