StringUtils.contains of Apache and Boyer–Moore string search algorithm

安稳与你 提交于 2020-01-03 17:43:36

问题


To search for s in S (size(S) >= size(s) and return a true/false value), it's better for performance to use StringUtils.contains() of Apache or use Boyer-Moore algorithm implemented and tested well by someone I found?

Thanks


回答1:


The last time I looked into the Java regex matching code while debugging, the Java 7 regex engine used the Boyer-Moore algorithm for sequences of literal text matches. So the easiest way to find a String using Boyer-Moore is to prepare using p=Pattern.compile(searchString, Pattern.LITERAL) and search using p.matcher(toSearchOn).find(). No third party libraries and no handcrafted work needed. And I believe the JRE classes are tested well…




回答2:


Apache Lang uses the Java API's Region Matching for their contains implementation. Hard to say which is faster on the surface. Sounds like an opportunity to build a simple test case and run it both ways and see.



来源:https://stackoverflow.com/questions/20005690/stringutils-contains-of-apache-and-boyer-moore-string-search-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!