-2

The question is how to implement a stack of integers in an array in Java Collection Framework as a variable-size array?

2
  • 1
    Can you give more details on your request ? do you need to implement a LIFO data structure ? if yes, it already exist by default in java ... Commented Feb 5, 2016 at 11:59
  • I suggest you read how Stack in the JDK is implemented as it does this (except for references) Commented Feb 5, 2016 at 12:01

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The GS Collections library is now an Eclipse project: projects.eclipse.org/proposals/eclipse-collections eclipse.org/collections
Also, in the core JDK, java.util.ArrayDeque is a better stack than java.util.Stack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.