Reputation: 1477
Is it advisable to use java.text.MessageFormat
to do operations on Strings? Or any alternative?
Upvotes: 0
Views: 865
Reputation: 6738
The advantages of using MessageFormat are
The disadventages of using MessageFormat is
Upvotes: 0
Reputation: 533580
IMHO, MessageFormats are particularly useful when you need to define them externally, e.g. via a Resource.
You can have different MessageFormats for different languages and they can present your fields in a different order suitable to the language.
For the simplest of needs I would use String +
e.g.
out.println("Message: " + message+", count: "+ count);
For more complex formatting needs I would use String format.
put.printf("Percent %6.2f%%, bytes: %,d%n", percent, byteCount);
Where you need to be able to configure your message format, I believe MessageFormat is likely to be the best option.
Upvotes: 1