I need to go something like:
public String func (String str){
str = str.replace("aaa","bbb");
str = str.replace("ccc","ddd");
str = str.replace("eee","fff");
return str;
}
Is there a more efficient way to do so? i guess that every replace function complexity is O(n), so three times calling replace will be O(3n). I am sure it is possible to be implemented in O(n), is there a simple way to do so with JAVA ??
(and an elegant way to do so with JAVA 8 in case the replacement input comes from a function like str.replace("aaa", getFirstReplacement()) ).