You can use indexOf to search for currStr. If the indexOf method returns -1, then there is no match. Another number will be the starting location of the substring.
if(initialStr.indexOf(currStr) == -1) { initialStr += currStr; }
Alternatively, if it doesn't matter, you can add toLowerCase () or toUpperCase () in the above code example:
if(initialStr.toLowerCase().indexOf(currStr.toLowerCase()) == -1) { initialStr += currStr; }
If you have a lot of string operations, I recommend looking at the StringUtils class from the Apache Commons Lang library. It provides many useful methods. Here is the API link: http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringUtils.html
source share