How to implement a SQL like 'LIKE' operator in java?

后端 未结 15 1480
你的背包
你的背包 2020-11-29 03:12

I need a comparator in java which has the same semantics as the sql \'like\' operator. For example:

myComparator.like(\"digital\",\"%ital%\");
myComparator.l         


        
15条回答
  •  广开言路
    2020-11-29 04:09

    Regular expressions are the most versatile. However, some LIKE functions can be formed without regular expressions. e.g.

    String text = "digital";
    text.startsWith("dig"); // like "dig%"
    text.endsWith("tal"); // like "%tal"
    text.contains("gita"); // like "%gita%"
    

提交回复
热议问题