array

Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

ArrayList vs LinkedList vs Vector


ArrayList vs LinkedList vs Vector 


ArrayList
LinkedList
Vector
Data structureIndex-based  dynamic arrayDoubly linked listGrowable array
Increment size50%No initial size100%
Traverse Uses iteratorUses iteratorUses enumeration
Memory usageLess memory usageMore memory usage
AccessibilityRandom and fastSequential and slowRandom and fast
OrderInsertion orderInsertion orderInsertion order
DuplicatesAllowAllowAllow
Insert / DeleteSlowFastSlow
SynchronizedNoNoYes
ImplementsRandomAccess interfaceNA
RandomAccess interface &
Serializable interface
Null valuesYesYesYes

Array vs ArrayList


 

Array
ArrayList
Fixed-sizeSize is not fixed
Not type-safeType-safe
Allow both primitives and objectsDoesn't allow primitives. But after Java 5 auto-boxing will convert primitives to objects

Type safety means the compiler will validate the types while compiling and throw an error if you do anything wrong.