For example, I have a String "PARAMS @ FOO @ BAR @" and String array {"one", "two", "three"}.
How would you map the array values one-to-one to the string (replace the markers), so that in the end I would get: "PARAMS one, FOO two, BAR three".
Thank you
You could just do
String str = "PARAMS @ FOO @ BAR @";
String[] arr = {"one", "two", "three"};
for (String s : arr)
str = str.replaceFirst("@", s);
After this, str would hold "PARAMS one FOO two BAR three". Of course, to include the commas you could just replace with s + ",".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With