Cannot create a Java Stack

Question:
I’m getting an error when I try to create a Stack.

Repl link:
https://replit.com/@hbijli/FirstJava#Collections/MyStack.java

import java.util.*;

class MyStack {

  public static void main(String[] args) {

    //Issue with replit. Use another IDE.
    Stack <Integer> stack = new Stack <Integer>();

    for (int i = 0; i < 10; i++) {
      stack.push(i);
    }

    System.out.println(stack.size());
  }
}

Hi @hbijli I think you have created the Repl using the wrong template.

I just recreated your code using a Java template and it worked first time.

The icon background for the Java template should be dark blue not white. Hope this helps.

Thank you Ian. That worked. I was trying to move my other files to the Java template. I couldn’t find an option to do it. It’s not a big deal though.

2 Likes