I've been using MessageFormat.format()
for a while, but there's one thing that I find annoying.
Everytime you declare a parameter in a message, you have to know the position of the mapped argument. e.g.
MessageFormat.format("{0} is annoying {1}.", "this", "indeed")
Is there a class that is the same as MessageFormat
in every other way but lets you omit the argument position in parameter declaration altogether and have it default to its position in the message so that the first parameter maps to the first argument, the second parameter to the second argument and so on? e.g.
MessageFormat.format("{} is much better{}.", "this", "indeed")
I think later versions of log4j have a similar feature, but I just need the formatting class.
Happy New Year!
EDIT: I need this feature for assertion, so it's really for internal use, but I appreciate your insight into why MessageFormat works the way it does.
You should be using Formatter
or its frontend, String.format
, instead. You can do:
String.format("%s is much better %s", "this", "indeed");
String.format("%1$s provides positional formatting %2$s", "this", "indeed");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With