I\'m looking for something to achieve the following:
String s = \"hello {}!\";
s = generate(s, new Object[]{ \"world\" });
assertEquals(s, \"hello world!\");
There are two solutions:
Formatter is more recent even though it takes over printf() which is 40 years old...
Your placeholder as you currently define it is one MessageFormat can use, but why use an antique technique? ;) Use Formatter.
There is all the more reason to use Formatter that you don't need to escape single quotes! MessageFormat requires you to do so. Also, Formatter has a shortcut via String.format() to generate strings, and PrintWriters have .printf() (that includes System.out and System.err which are both PrintWriters by default)