Issue
Below is the string of values separated by commas. Need to filter each values and append them with specific values.
String values - Hello, MyName, Is, XYZ
Above is the string that i am sending through an API
What i want is - How to add (_true)
this string value to each element on above String Values. That also to few String values that i am checking with some specific condition
So that it should be like below in that API call which is sent to FrontEnd.
Hello(_true), MyName, Is, XYZ(_true)
Solution
public static String StringAppenderWithLogic(String given, String del) {
return String.join(del, Arrays.stream(given.split(del)).
map(p -> {
//put any logic specific to your requirement
if (p.trim().startsWith("H") || p.trim().startsWith("X")) {
p = p + "(_true)";
}
return p;
}).collect(Collectors.toList()));
}
Answered By - anurag saxena
Answer Checked By - Gilberto Lyons (JavaFixing Admin)