任何类似于Java中的sprintf的方法?

use*_*949 8 java formatter

在Java中使用sprintf的任何类似方法?

Gus*_*ind 13

在某种程度上,String.format就像这里有一个Java sprintf方法

String status = String.format("The rename status is (%d)", RENAME_SUCCEEDED);
Run Code Online (Sandbox Code Playgroud)

你也可以在这里看到这个例子


Vla*_*nov 10

您正在寻找

String.format.


Dew*_*wfy 8

复杂的方式(使用Formatter)

StringBuilder sb = new StringBuilder();
// Send all output to the Appendable object sb
Formatter formatter = new Formatter(sb, Locale.US);

// Explicit argument indices may be used to re-order output.
formatter.format("%4$2s %3$2s %2$2s %1$2s", "a", "b", "c", "d")
Run Code Online (Sandbox Code Playgroud)

或者更简单的方法:

String.format
Run Code Online (Sandbox Code Playgroud)