java - 在 Java 中将二维整数数组压入堆栈

标签 java multidimensional-array stack

我有一个二维整数数组 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/

相关文章:

java - Tomcat 8.5 : Required String parameter '...' is not present

java - 石头、剪刀、布机器人

java - 为什么getResource返回null

java - QR 码扫描仪库支持 Marshmallow?

python - 减去二维数组中每行的第一个元素

arrays - perl文件操作

php - 如何在 PHP 中构建多维数组

c++ - 设计题: How can I maintain a stack of object

c - C中的函数压入栈

c - 堆栈 eip 溢出 x86 与 x86_64 简单的 C 代码