How to check if a String contains another String in a case insensitive manner in Java?

前端 未结 19 1657
渐次进展
渐次进展 2020-11-22 03:20

Say I have two strings,

String s1 = \"AbBaCca\";
String s2 = \"bac\";

I want to perform a check returning that s2 is contained

19条回答
  •  滥情空心
    2020-11-22 04:16

    You can use

    org.apache.commons.lang3.StringUtils.containsIgnoreCase("AbBaCca", "bac");
    

    The Apache Commons library is very useful for this sort of thing. And this particular one may be better than regular expressions as regex is always expensive in terms of performance.

提交回复
热议问题