Java字符串右对齐
我有一些这些数字
61672 8414449 264957
我使用像这样的DecimalFormat
对象
DecimalFormat formatter = new DecimalFormat("###,### bytes");
得到这些结果
61,672 bytes 8,414,449 bytes 264,957 bytes
但我需要将结果与以下内容对齐
61,672 bytes 8,414,449 bytes 264,957 bytes
您的帮助已经受到赞赏。
您可以将它包装到String.format
调用中,如下所示:
String.format("%15s", formatter.format(i))