Java collections framework: Difference between revisions

Content deleted Content added
List implementations: Add details about Vector and Stack
Make Stack a subheading of Vector
Line 115:
The {{java|Vector}} class has {{java|Stack}} as its direct subclass. This is an example of a violation of the [[composition over inheritance]] principle in the Java platform libraries, since in [[computer science]], a [[Vector (data structure)|vector]] is generally not a [[Stack (abstract data type)|stack]].{{sfn|Bloch|2018|loc=Chapter §4 Item 18: Favor composition over inheritance|pp=87-92}} Composition would have been more appropriate in this scenario.{{sfn|Bloch|2018|loc=Chapter §4 Item 18: Favor composition over inheritance|pp=87-92}}
 
======Stack class======
The Stack class <code>[[inheritance (object-oriented programming)|extends]]</code> class '''{{Javadoc:SE|module=java.base|package=java.util|java/util|Vector}}''' with five operations that allow a <code>Vector</code> to be treated as a <code>Stack</code>.
Stacks are created using '''{{Javadoc|module=java.base|package=java.util|class=Stack|monotype=y}}'''. The <code>Stack</code> offers methods to put a new object on the <code>Stack</code> (method {{Javadoc:SE|module=java.base|name=push(E e)|java/util|Stack|push(E)}}) and to get objects from the <code>Stack</code> (method {{Javadoc:SE|module=java.base|name=pop()|java/util|Stack|pop()}}). A <code>Stack</code> returns the object according to [[Stack (abstract data type)|last-in-first-out]] (LIFO), e.g. the object which was placed latest on the <code>Stack</code> is returned first. <code>java.util.Stack</code> is a standard implementation of a stack provided by Java.