Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
IBM : developerWorks : Java : Education - online courses
Java Collections Framework
Download tutorial zip fileView letter-sized PDF fileView A4-sized PDF fileE-mail this tutorial to a friend
Main menuSection menuGive feedback on this tutorialPreviousNext
5. Historical collection classes
  


Vector and Stack classes page 3 of 7


A Vector is a historical collection class that acts like a growable array, but can store heterogeneous data elements. With the Java 2 SDK, version 2, the Vector class has been retrofitted into the Collections Framework hierarchy to implement the List interface. However, if you are using the new framework, you should use ArrayList, instead.

When transitioning from Vector to ArrayList, one key difference is that the arguments have been reversed to positionally change an element's value:

  • From original Vector class
    void setElementAt(Object element, int index)
  • From List interface
    void set(int index, Object element)

The Stack class extends Vector to implement a standard last-in-first-out (LIFO) stack, with push() and pop() methods. Be careful, though. Because the Stack class extends the Vector class, you can still access or modify a Stack with the inherited Vector methods.


Main menuSection menuGive feedback on this tutorialPreviousNext
PrivacyLegalContact