使用MessageFormatter.format替代 String.format
现有的J2EE 项目中基本都会引用 日志框架,刚好 日志框架中有对应的工具类可以使用,对数据进行格式化:
import org.slf4j.helpers.MessageFormatter;
String format1 = String.format("%s/%s", 1, 2);
String format2 = MessageFormatter.format("{}/{}", 1,2).getMessage();
System.out.println(format1);
System.out.println(format2);