How to build a formatted string in Java?
Since JDK 15:
var s = "x:%d, y:%d, z:%d".formatted(x, y, z);
String s = String.format("x:%d, y:%d, z:%d", x, y, z);
Java Howto - Format a string
Yes, it is possible. The String
class contains the format()
method, which works like you expect.
Example:
String s = String.format("x:%d, y:%d, z:%d", x, y, z);
Here you have more details about formatting: formatter syntax