Java字符串向右对齐
我有这些数字的数组Java字符串向右对齐,java,formatter,Java,Formatter,我有这些数字的数组 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 我们已经感谢您的帮助
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("%15s", formatter.format(i))
可能重复:直接前进。谢谢@David OP定义了那个对象。