如何在StrSubstitutor中使templateString动态化

时间:2017-11-24 12:36:26

标签: java arrays apache-commons-lang apache-commons-lang3

String[] greetings = {"Hello1", "Hello2", "Hello3"};  
String otherString = "green";
Map<String, String[]> valuesMap = new HashMap<String, String[]>();
valuesMap.put("greeting", greetings);
valuesMap.put("color", otherString );

String templateString = "Its ${color} around. ${greeting} StrSubstitutor APIs.";
StrSubstitutor sub = new StrSubstitutor(valuesMap);
String resolvedString = sub.replace(templateString);

我正在寻找类似于:

的输出
Its green around. Hello1 StrSubstitutor APIs.
or Hello2 StrSubstitutor APIs
or Hello3 StrSubstitutor APIs.

任何建议都会有所帮助。

0 个答案:

没有答案