我需要将一组通过数组的值替换为格式化的字符串。见下面的例子,
String value="abc {0} def {1} ghi {2}";
String[] replacingValue={"T1","T2","T3"};
//{i} values should be replaced with T1,T2...etc.
String result="abc T1 def T2 ghi T3";
无论如何我们可以使用Spring SpEL做到这一点吗?
答案 0 :(得分:0)
这应该有效
String value = "abc {0} def {1} ghi {2}";
String[] replacingValue = { "T1", "T2", "T3" };
// {i} values should be replaced with T1,T2...etc.
String result = MessageFormat.format(value, replacingValue);
System.out.println(result);