我有一个包含此类{0},{1} ... {n}这样的表达式的字符串。而且我有n个长度的字符串列表。 {0}替换为param [0],{1}替换为param [1],{n}替换为param [n]。我怎样才能做到这一点?

List<String> params = new ArrayList<String>;
param[0] = "dortmund";
param[1] = "5555";
String message = "customers address is  {0}, phone number is {1}, please check them.";

最佳答案

您可以使用MessageFormat

MessageFormat messageFormat = new MessageFormat("customers address is  {0}, phone number is {1}, please check them.");
Object[] args = {"dortmund", "5555"};
String message = messageFormat.format(args);

07-24 18:55
查看更多