A better java.text.MessageFormat.
// parse to immutable formatter
var expression = FormatExpression.parse("Hello, {0}!");
// format
String result = expression.format(Locale.getDefault(), "World");
// print "Hello, World!"
System.out.println(result);
- Immutable, thread-safe parsed expressions
- Supports JDK23 expressions at lower JDK versions
- Exposes more parsed expression metadata
FormatExpression
uses the same format types for numbers, lists and date/times asMessageFormat
for compatibility reasons- Parsing
ListFormat
expressions like
{0,list}
is supported in JDK8+ but formatting such expressions requires a JDK22+ runtime - Format types attempt to solve two problems - format and parse; this library only formats
Source and target are JDK8. Requires JDK23 to execute unit tests.
Use Maven wrapper scripts to build:
code/format/mvnw -f code/format/pom.xml clean install
Published artifacts can be found in the Maven Central Repository.