I have string say "ABC,D" , now I wish to write a method append(initialStr, currStr )
which appends currStr
to initailStr
only if currstr is not already present in initialStr
. I tried a method which splits with comma, but since my string contains comma so that method doesn't works for me. Any help will be greatly appreciated.
String appendIfNotPresent(String initial, String curr)
{
if (initial.contains(curr))
return initial;
else
return initial + curr;
}
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