它不是连接,而是合并两个数组,使它们成为名称值对的数组。
firstarray = ["a","aa","aaa"]
secondarray = ["b","bb","bbb"]
result = [["a","b"],["aa","bb"],["aaa","bbb"]]
最好的方法是什么?
最佳答案
在 Java 中:
public static int [][] concat(int a[], int b[]) {
int res[][] = new int[a.length][2];
if (a.length != b.length) {
throw new IllegalArgumentException("lenght are not equal, cannot perform");
}
for (int i = 0; i < a.length; i++) {
res[i][0] = a[i];
res[i][1] = b[i];
}
return res;
}
关于java - Java中如何合并两个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4459258/