You can use the String.format(...) method to compile an error, logging, or any other String messages. Unfortunately, this method is not type safe, so the next source will throw an IllegalFormatException
String s = String.format("My message has %d characters !", "30");
Is there any other alternative for composing such messages besides the StringBuilder class.
My personal opinion is that a complex message becomes harder to read with an instance of StringBuilder.
java string
My-name-is
source share