我有一个二维整数数组 array[i][j] (for 循环内的 for 循环),我想将 i 和 j 值插入二维堆栈。
我已将堆栈定义如下:
Stack<Integer[][]> stack = new Stack<Integer[][]>()
;
如何将 i 和 j 压入堆栈?
我已经尝试过:
stack.push([i][j]);
但是 Eclipse 吐出:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem: Syntax error on token "(", Expression expected after this token
最佳答案
编译器会抛出错误,因为您的代码语法无效。您取消引用不存在的数组并尝试错误地将它们的值传递给堆栈函数。尝试更多类似的事情:
stack.push(new Integer[][] {{i}, {j}});
关于java - 在 Java 中将二维整数数组压入堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9696827/