String stringFormat = "lexical error at position %s, encountered %s, expected %s ";
String messageFormat ="lexical error at position {0}, encountered {1}, expected {2}";
System.out.println(String.format(stringFormat, 123, 100, 456));
System.out.println(MessageFormat.format(messageFormat, new Date(), 100, 456));
运行结果:
两种方式主要是占位符不一样,如果需要使用高级功能建议是使用MessageFormat。