1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

Java Tutorials

Q.Difference between Vector and ArrayList?

Vectors are synchronized. Any method that touches the Vector's contents is thread safe.
ArrayList, on the other hand, is unsynchronized, making them, therefore, not thread safe.
With that difference in mind, using synchronization will incur a performance hit.
So if you don't need a thread-safe collection, use the ArrayList don't use Vector.

A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.
Depending on how you use these classes, you could end up taking a large performance hit while adding new elements.
If you don't know how much data you'll have, but you do know the rate at which it grows, Vector does possess a slight advantage since you can set the increment value.

Both the ArrayList and Vector are good for retrieving elements from a specific position in the container or for adding and removing elements from the end of the container.
All of these operations can be performed in constant time -- O(1).
However, adding and removing elements from any other position proves more expensive -- linear to be exact: O(n-i), where n is the number of elements and i is the index of the element added or removed.
For Example : ArrayList Has 5 elements and you want to add an element on 2nd position.
Then arrayList add the element on 2nd position and shifted existing 2nd position element to 3rd , 3rd position element to 4th etc..
For the case of remove just opposite.
These operations are more expensive because you have to shift all elements at index i and higher over by one element

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy