It's all fine if you're used to numbered placeholders e.g. {0} and {1}. Since I'm used to Drupal's format_string() function, here's a better alternative. Apache Commons has a StrSubstitutor class which allows use of named placeholders. Instead of using:
String template = "Welcome {0}! Your last login was {1}"; String output = MessageFormat.format(template1, new Object[] { "gabe", new Date().toString() });
You can now do:
String template = "Welcome ${username}! Your last login was ${lastlogin}"; Mapdata = new HashMap (); data.put("username", "gabe"); data.put("lastlogin", new Date().toString()); String output2 = StrSubstitutor.replace(template2, data);
Although StrSubstitutor is a bit more verbose, but it helps when you're handling lots of key/value pairs.