I am trying to use StrSubstituor API to substitute array values. So far, it just ends up substituting the array.toString value.
String[] greetings = {"Hello", "World"};
Map<String, String[]> valuesMap = new HashMap<String, String[]>();
valuesMap.put("greeting", greetings);
String templateString = "${greeting} StrSubstitutor APIs.";
StrSubstitutor sub = new StrSubstitutor(valuesMap);
String resolvedString = sub.replace(templateString);
The result should be:
Hello World StrSubstitutor APIs.
However, now it prints something like:
[Ljava.lang.String;@4c011fe StrSubstitutor APIs.
Let me know if you need more information. Any pointers would be greatly appreciated. If this is not the way to do this, please suggest what is the best way to do it. Sorry, if I am in completely wrong on this one.
However, now it prints something like:
[Ljava.lang.String;@4c011fe StrSubstitutor APIs.
It seems like you are trying to print out an String[]
. Try to use Arrays.toString()
.
In your post, you need to replace this line:
valuesMap.put("greeting", greetings);
With this:
valuesMap.put("greeting", Arrays.toString(greetings));