@Test public void testFormat2() { String fmt = "Some string {} 2 {}"; assertEquals("Some string 1 2 3", format(fmt, 1, "3")); }
public static String format(String source, Object... parameters) { String current = source; for (Object parameter : parameters) { if (!current.contains("{}")) { return current; } current = current.replaceFirst("\\{\\}", String.valueOf(parameter)); } return current; }
PositionalParameterStringFormatter { public static String format(String source, Object... parameters) { String current = source; for (Object parameter : parameters) { if (!current.contains("{}")) { return current; } current = current.replaceFirst("\\{\\}", String.valueOf(parameter)); } return current; } }
PositionalParameterStringFormatter { public static String format(String source, Object... parameters) { String current = source; for (Object parameter : parameters) { if (!current.contains("{}")) { return current; } current = current.replaceFirst("\\{\\}", String.valueOf(parameter)); } return current; } private  PositionalParameterStringFormatter(); }
PositionalParameterStringFormatter { public static String format(String source, Object... parameters) { String current = source; for (Object parameter : parameters) { if (!current.contains("{}")) { return current; } current = current.replaceFirst("\\{\\}", String.valueOf(parameter)); } return current; } private  PositionalParameterStringFormatter(); static String format(String source, Object... parameters); }
PositionalParameterStringFormatter { public static String format(String source, Object... parameters) { String current = source; for (Object parameter : parameters) { if (!current.contains("{}")) { return current; } current = current.replaceFirst("\\{\\}", String.valueOf(parameter)); } return current; } private  PositionalParameterStringFormatter(); static String format(String source, Object... parameters);  }