### Question:
MessageFormat { public static String format(String pattern, Object... arguments) { String msg = pattern; if (arguments != null) { for (int index = 0; index < arguments.length; index++) { msg = msg.replaceAll("\\{" + (index + 1) + "\\}", String.valueOf(arguments[index])); } } return msg; }  static String format(String pattern, Object... arguments);  }### Answer:
@Test public void test() { Assert.assertEquals(MessageFormat.format("{1} {2} {1}", new Object[] { "1", "2" }), "1 2 1"); Assert.assertEquals(MessageFormat.format("{1} is a {2}", new Object[] { "This", "test" }), "This is a test"); Assert.assertEquals(MessageFormat.format("{1} is a {2}", new Object[] { "This", "test", "test", "test" }), "This is a test"); Assert.assertEquals(MessageFormat.format("{1} {2} {1}", new Object[0]), "{1} {2} {1}"); Assert.assertEquals(MessageFormat.format("{1} {2} {1}", (Object[]) null), "{1} {2} {1}"); }