为什么我的字符串不是固定大小的?
why is my string not in fixed size?
我尝试打印带填充的字符串(table 喜欢):
StringBuilder sb = new StringBuilder();
sb.append(String.format("%1s", "bulk name"));
sb.append(String.format(" | "));
sb.append(String.format("%1s", "baseline"));
sb.append(String.format(" | "));
sb.append(String.format("%1s", "current"));
sb.append(String.format(" | "));
sb.append("\n");
for (int i = 0; i < baseLine.tillOneSecondBulks.size(); i++) {
sb.append(String.format("%1s", baseLine.tillOneSecondBulks.get(i).bulkName));
sb.append(String.format(" | "));
sb.append(String.format("%1s", baseLine.tillOneSecondBulks.get(i)
.count));
sb.append(String.format(" | "));
sb.append(String.format("%1s", current.tillOneSecondBulks.get(i)
.count));
sb.append(String.format(" | "));
sb.append("\n");
sb.append("\n");
}
sb.append("\n");
sb.append("\n");
但仍未订购:
bulk name | baseline | current |
[0,0.2) seconds | 0 | 0 |
[0.2,0.4) seconds | 0 | 0 |
[0.4,0.6) seconds | 0 | 0 |
[0.6,0.8) seconds | 0 | 1 |
[0.8,1) seconds | 1 | 0 |
尝试增加 header 的长度以及第一个字段的每一行。原因如果你看到例如[0.2,0.4) seconds
长度超过 15 个字符。
尝试将其增加到 20 个字符,这将解决问题。
我尝试打印带填充的字符串(table 喜欢):
StringBuilder sb = new StringBuilder();
sb.append(String.format("%1s", "bulk name"));
sb.append(String.format(" | "));
sb.append(String.format("%1s", "baseline"));
sb.append(String.format(" | "));
sb.append(String.format("%1s", "current"));
sb.append(String.format(" | "));
sb.append("\n");
for (int i = 0; i < baseLine.tillOneSecondBulks.size(); i++) {
sb.append(String.format("%1s", baseLine.tillOneSecondBulks.get(i).bulkName));
sb.append(String.format(" | "));
sb.append(String.format("%1s", baseLine.tillOneSecondBulks.get(i)
.count));
sb.append(String.format(" | "));
sb.append(String.format("%1s", current.tillOneSecondBulks.get(i)
.count));
sb.append(String.format(" | "));
sb.append("\n");
sb.append("\n");
}
sb.append("\n");
sb.append("\n");
但仍未订购:
bulk name | baseline | current |
[0,0.2) seconds | 0 | 0 |
[0.2,0.4) seconds | 0 | 0 |
[0.4,0.6) seconds | 0 | 0 |
[0.6,0.8) seconds | 0 | 1 |
[0.8,1) seconds | 1 | 0 |
尝试增加 header 的长度以及第一个字段的每一行。原因如果你看到例如[0.2,0.4) seconds
长度超过 15 个字符。
尝试将其增加到 20 个字符,这将解决问题。