How do you initialize a stack to be empty in java?

I’m given

   private Stack<Double> stack

When creating the default constructor I’m asked as follows:

  "Initialize stack to be an empty Stack to hold double data values"

I’ve tried something along the lines of stack.empty() but I’m guessing empty() functions the same as isEmpty() which isn’t much help. Does anyone know how to initialize an empty stack?


When a Stack object is created it is empty by default. So a mere

private Stack<Double> stack = new Stack<>();

would be enough to initialize it empty.

You can also initialize the stack in the constructor of your class if you don’t want to separate its declaration and initialization:

class YourClass {
  private Stack<Double> stack;

  public YourClass() {
    this.stack = new Stack<>();