java - How to concatinate two columns in same array? -
how concatinate 2 columns in same array?
example:
aa ab ac ad 1 0 2 0 2 1 3 3 3 3 0 2 0 2 1 1
output:should this.
aaab aaac aaad abac abad acad 10 12 10 02 00 20 21 23 23 13 13 33 33 30 32 30 32 02 02 01 01 21 21 11
how can code in java ?
for (int = 0; < row.size(); i++){
for (int j = 0; j < col.size(); j++) {
for (int k = j + 1; k < col.size(); k++) {
col1.add(val[j]);
col2.add(val[k]);
finalval.add(col1.get(j) + col2.get(k));
}
}
system.out.println("finalval");
}
public static void main(string[] args) { string[][] input = new string[][] { { "aa", "ab", "ac", "ad" }, { "1", "0", "2", "0" }, { "2", "1", "3", "3" }, { "3", "3", "0", "2" }, { "0", "2", "1", "1" } }; string[][] output = new string[input.length][]; (int = 0; < output.length; i++) output[i] = concat(input[i]); print(output); } private static string[] concat(string[] strings) { int n = strings.length; string[] result = new string[(n * (n - 1)) / 2]; int m = 0; (int = 0; < n; i++) (int j = + 1; j < n; j++) if (i != j) result[m++] = strings[i] + strings[j]; return result; } private static void print(string[][] strings) { (int = 0; < strings.length; i++) system.out.println(arrays.aslist(strings[i])); }
Comments
Post a Comment