我在这里有两个具有预定义值的字符数组。我想从两个数组中获得变化。
这是两个数组的预定义值:
Character[][] arr1 = new Character[row][column];
arr1[1][0] = 'K';
arr1[1][1] = 'E';
arr1[1][2] = 'P';
arr1[1][3] = 'T';
Character[][] arr2 = new Character[row][column];
arr2[0][1] = 'H';
arr2[1][0] = 'K';
arr2[1][1] = 'E';
arr2[1][2] = 'P';
arr2[1][3] = 'T';
arr2[2][1] = 'L';
arr2[3][1] = 'P';
使用此代码,我得到了正确的“HLP”更改
final Character[][] arr3 = new Character[row][column];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (arr1[i][j] != arr2[i][j]) {
s = arr2[i][j];
arr3[i][j] = s;
}
}
}
//generate the word from the compared arrays
for (int r = 0; r < 4; r++) {
for (int c = 0; c < 4; c++) {
if (arr3[r][c] != null) {
l = arr3[r][c];
k = Character.toString(l);
out = builder.append(k).toString();
}
}
}
现在,我想在H
and之间包含空格L
并将其包含在我的字符串中。任何人都可以告诉我如何做到这一点吗?