应该是一个简单的,但我想根据条件将“一”,“一”,“一”或“二”,“二”,“二”添加到二维数组
String[][] headings = new String[][] { {
"three",
"three",
"three"
} };
最佳答案
我不太明白你想如何确定数组的尺寸。如果添加后您将有 6 个元素,它们将如何放置? 1×6? 2×3?无论如何,您可以使用 ArrayList<String[]>
:
ArrayList<String[]> headings = new ArrayList<String[]>();
headings.add(new String[] { "three", "three", "three" });
if(/* condition */)
headings.add(new String[] { "two", "two", "two" });
else
headings.add(new String[] { "one", "one", "one" });
关于java - 追加到二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9007868/