File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes When do we use ArrayList, Vector and LinkedList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "When do we use ArrayList, Vector and LinkedList" Watch "When do we use ArrayList, Vector and LinkedList" New topic
Author

When do we use ArrayList, Vector and LinkedList

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
ArrayList : when we need fast iteration

Vector : when we need thread safety since Vector methods are synchronised by default.

LinkedList: when do we use linkedlist ??

Also any practical examples, where we could use each of the above ?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

ArrayList is fast in random access. If I want to get the 8th element then the 3rd element then the 7th and then the 2nd element, ArrayList will provide the best performance. LinkedList is slow in random access

LinkedList is used when you modify the list a lot. If you'll add and remove elements to the List a lot of times, LinkedList should be used. ArrayList is slow in terms of additions and removal...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
Don't get me started about those stupid light bulbs.
 
subject: When do we use ArrayList, Vector and LinkedList