I have a map which contains regexpr as key and replacer as value and I need to perform a replaceAll for each string in a list.
I should like to know if my answer is correct or if there exists a better way to do that, I'm afraid to see the performance drop. Cause I need to perform this operation on a lot of lists which contain lots of strings.
Map<String,String> m_replace = null; //Map which contains regexpr,replacer
private static String replace(String s) {
for (Map.Entry<String, String> entry : m_replace.entrySet())
s = s.replaceAll(entry.getKey(), entry.getValue());
return s;
}
public List<String> parseList(List<String> input) {
return input.parallelStream()
.map(p -> p = replace(p))
.collect(Collectors.toList());
}
replaceAll(meaning that the pattern was actually found), shouldn't you stop processing all other map entries?Listyou will have to traverse the entireMapthen...O(n)for the list timesO(n+c)for theMap; where c - is the capacity of the map and n are the number of entries. That would be a total ofO(npow2).