我正在结合两个矩阵:
矩阵A =
719.0 501.0 -75.0
501.0 508.0 -62.0 -75.0
-62.0 10.0
矩阵B =
-19.0 -19.0 -19.0 -19.0 -19.0 -19.0 -19.0 -19.0 -19.0 -19.0
-20.0 -20.0 -20.0 -20.0 -20.0 -20.0 -20.0 -20.0 -20.0 -20.0
0.0 0.0 0.0 0.0 0.0 0.000.0 0.0 0.00.0.0
matrixA#matrixB- 使用#
和组合
该行使用,
和分隔
使用分隔的元素|
我的 toString 代码是:
public String toString() {
String separator = "|";
StringBuffer result = new StringBuffer();
for (int k = 0; k < keys.length; k++) {
for(int l = 0; l < keys[k].length; l++){
result.append(keys[k][l]);
result.append(separator);
}
result.setLength(result.length() - separator.length());
// add a line break.
result.append(",");
}
result.append("#");
for (int i = 0; i < values.length; i++) {
for(int j = 0; j < values[i].length; j++){
result.append(values[i][j]);
result.append(separator);
}
// remove separator
result.setLength(result.length() - separator.length());
// add a line break.
result.append(",");
}
return result.toString();
}
我的结果是:
719.0|501.0|-75.0,501.0|508.0|-62.0,-75.0|-62.0|10.0 ,
#-19.0|-19.0|-19.0|-19.0|-19.0|-19.0|-19.0|-19.0|-19.0|- 19.0,-20.0|-20.0|-20.0|-20.0|-20.0|-20.0|-20.0|-20.0|-20.0|-20.0,0.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0| 0.0,
如何删除最后一个分隔符?