Open In App

What are the negative aspects of Java Stack class inheriting from Vector?

Improve
Improve
Like Article
Like
Save
Share
Report

Java Vector:

Vectors are analogous to arrays in a way that both of them are used to store data, but unlike an array, vectors are not homogeneous and don’t have a fixed size. They can be referred to as growable arrays that can alter their size accordingly. It is relatively a memory-efficient way of handling lists whose size could change drastically. 

It is found in “java.util” package and implements the List interface as displayed in the figure below:

List interface used by vector

List interface used by vector

To learn more about vector class in Java refer to the article “Vector class in Java“.

Stack Class:

A Stack is a data structure where elements can be inserted and deleted from the front end also known as the ‘Top’ of the stack. 

Insertion in Stack is given a standard name Push and deletion is given a standard name Pop. This class can also be referred to as the subclass of Vector. The Stack class in Java is an extension of the “Vector” class.

Negative aspects of Java Stack class inheriting from Vector class:

The negative aspects of the Java Stack class inheriting from the Vector class are mentioned below:

  • Stack uses the last-in-first-out (LIFO) system, but after inheriting from Vector, Stacks show properties that are very different from its description, like accessing an element from a specific index, including the potential for index exceptions etc, which contradict the definition and implementation.
  • Stack is a class and not an interface that diverges from the implementation of the collection framework where the data structure is typically represented by an interface.
  • Stack is now bound to the Vector and one cannot easily provide his stack implementation.

Last Updated : 08 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads