I'm trying to find the most efficient way of removing a character sequence in Java. Note that I don't care if I only remove one instance of the sequence or all of them as long as it is efficient.
Ex. I have a string s = "aabbccddeeffcc"
. If I do s.replace("cc", "")
am I correct in assuming that it is constant time? If not, is there an efficient way of doing this? (The output of this operation could be aabbddeeffcc
, aabbccddeeff
or aabbddeeff
, but which it is is not as important to me.)
I've heard that StringUtils.replace might be a faster method, but couldn't find time complexity for that either.