Regex Optimization for large lists

后端 未结 4 448
逝去的感伤
逝去的感伤 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:05

    I think that you shouldn't use regex for that: I believe that looking into String#contains (here is a link to its javadoc entry) would give you better results, in terms of performance ;)

    For example, your code could be:

    for(final String s2: test2){
        for (final String s: test){
            if(s.contains(s2)) {
                System.out.println("Match");
            }
        }
    }
    

提交回复
热议问题