I am comparing two lists of strings to find possible matches. Example:
public class Tester {
public static void main(String[] args) {
List
IMHO methods like String.matches(String)
should be forbidden. Maybe you need a regex match, maybe not, but what happens here, is that you string gets compiled into an regex... again and again.
So do yourself a favor and convert then all into regexes via Pattern.compile
and reuse them.
Looking at your ".*" + s2 + ".*"
, I'd bet you need no regex at all. Simply use String.contains
and enjoy the speed.