Regex Optimization for large lists

后端 未结 4 442
逝去的感伤
逝去的感伤 2020-12-21 22:26

I am comparing two lists of strings to find possible matches. Example:

public class Tester {

    public static void main(String[] args) {

        List

        
4条回答
  •  [愿得一人]
    2020-12-21 23:03

    Instead of

    s.matches(".*" + s2 + ".*")
    

    you can use

    s.contains(s2)
    

    or

    s.indexOf(s2) > -1
    

    I tested both, each is about 35x faster than matches.

提交回复
热议问题