For composing error, logging or any other String
messages the String.format(...)
method can be used. Unfortunately this method isn't type safe, hence the follwoing source will throw an IllegalFormatException
String s = String.format("My message has %d characters !", "30");
Is there any other alternative for composing such messages, except of the StringBuilder
class.
My personal opinion is that the composed message gets harder to read by using a StringBuilder instance.