The problem I am solving is replacing all Strings from another String.
I solved this problem fairly easily on codingbat.com by using String.replaceAll, and doing it until the first String no longer contains the other String.
However, I dislike this method as it is very slow. I have tried searching this website for more efficient methods, and came across these questions:
Fastest way to perform a lot of strings replace in Java
String.replaceAll is considerably slower than doing the job yourself
They solved the problem by using StringUtils and Patterns. I still think these methods are too slow!
When I code problems like these, I like to get my runtime under two seconds with Java. I'm testing this with a String of 1,000,000 characters. String.replaceAll went well over two seconds, and so did the other two methods.
Does anyone have a fast solution for this problem? Thanks!
EDIT: Unfortunately, the answers I received still run too slowly. And yes, I did mean make a new String, not change the old String, sorry for that mistake.
I'm not sure how it would work, but I think looping over each char and checking might work. Something with algorithms.