Answer the question
In order to leave comments, you need to log in
Java: How to replace .replaceAll?
According to the analysis, methods using replaceAll take a long time.
Can this be optimized somehow?
Here is the code:
text = text
.replaceAll(dictAdverbs, "")
.replaceAll(serviceVocabulary, "")
.replaceAll("(?iu)(\\b([^\\s]{0,3})\\b)", "")
.replaceAll("(?iu)[^а-яa-z\\s]", " ")
.replaceAll("(?iu)([\\s]{2,})", " ")
.replaceAll("(?iu)(^[ ])", "");
Answer the question
In order to leave comments, you need to log in
Nothing, you just need to turn on your head and understand that you have a terrible overhead here for creating heaps of lines, which is just extremely slow, in addition, every time there is also a compilation of the regular expression, which also gives an overhead and take it to the grave that all this is also de then in the comparator which already means that it all fights a nightmarish number of times.
In total, you need to:
1) Compile all regular expressions once in advance.
2) Think about how such heavy operations ended up in the comparator.
3) It is possible to revise the entire set of regulars into 1 big regular season.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question