java - 追加到二维数组

标签 java

应该是一个简单的,但我想根据条件将“一”,“一”,“一”或“二”,“二”,“二”添加到二维数组

 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/

相关文章:

java - 二维数组中静态一维数组的问题

java - 是否有通过 Java 从 XML 模式生成 JSON 模式的工具?

java - 无法在单个单元测试中使用 maven 的 spring-boot-starter-test 方法 - Spring Boot

java - OpenAM + Spring Security SAML 获取 SAML 请求是无效响应

Java 项目到 Groovy - 库不起作用

java - 如何使用 HSQL 设置数据源进行 junit 测试

java - 在 Windows 上编译 Java 时访问被拒绝

java.io.IOException : unexpected end of stream on Connection (Android, jsoup)

java - Derby 外键约束

java - 如何在Spring测试环境中反序列化ClientResponse主体?