The question is how to implement a stack of integers in an array in Java Collection Framework as a variable-size array?
How to implement a stack of integers in array in Java Collection Framework as a variable-size array?
1 Answer
If stack of Integer boxed objects suites for you then you can just use java.util.Stack implementation from Java Collections. But if your requirement is to use only primitive types take a look at java.util.Stack implementation. All you need to do to make it work with primitive integer is just replace type of base array and all method parameters and return values. It's simple.
Third option is to use one of 3d party collection libraries, for example goldmnan sachs collections if I remember right. They provide such solution already.
2 Comments
Stuart Marks
The GS Collections library is now an Eclipse project: projects.eclipse.org/proposals/eclipse-collections eclipse.org/collections
Stuart Marks
Also, in the core JDK,
java.util.ArrayDeque
is a better stack than java.util.Stack
.
Stack
in the JDK is implemented as it does this (except for references)