+ 1

stack java frame collection could not work idk why it gives me error cannot take type stack parameter stack java frame

Import java.util.*; Public class StackB{ Public static void main(String args[]){ Stack<Integer> stack=new Stack<>(); stack.push(1); stack.push(2); stack.push(3); while(!stack.isEmpty()){ System.out.println(stack.peek()); stack.pop(); } } }

22nd Dec 2022, 9:51 AM
Khushi
1 Odpowiedź
+ 5
`Stack` instance is named <stack> - Notice lowercase letter 's' All the calls to push() and pop() refer to `Stack` class while they should instead be referring the instance <stack> Idk whether it was your keyboard's auto-cap feature or what, but the `import` and `public` reserved word were written with capital (uppercase) letter at their beginning. Mind you, Java is a case sensitive language ... (Edit) OP changed embedded snippet partially.
22nd Dec 2022, 10:01 AM
Ipang