作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下内容:
String[][] content = {
{"c","d", "2"},
{"e","f", "3"},
{"g","h", "4"},
{"i","j", "5"}} ;
如何将一些 1x3 元素添加到现有元素中?
最佳答案
public static void main(String[] args) {
String[][] content = {
{"c","d", "2"},
{"e","f", "3"},
{"g","h", "4"},
{"i","j", "5"}};
String[][] newContent = {{"p","a", "3"}};
System.out.println(Arrays.deepToString(append(content, newContent)));
}
public static String[][] append(String[][] a, String[][] b) {
String[][] result = new String[a.length + b.length][];
System.arraycopy(a, 0, result, 0, a.length);
System.arraycopy(b, 0, result, a.length, b.length);
return result;
}
输出
[[c, d, 2], [e, f, 3], [g, h, 4], [i, j, 5], [p, a, 3]]
另一个输入
String[][] content = {
{"c","d", "2"},
{"S","2"},
{"i","j", "5"},{"p","1"}};
String[][] newContent = {{"p","a", "3"},{"k","3"}};
输出
[[c, d, 2], [S, 2], [i, j, 5], [p, 1], [p, a, 3], [k, 3]]
关于java - 如何向 String[][] 追加元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39660837/
我是一名优秀的程序员,十分优秀!