As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center作为指导。
                            
                        
                    
                
                                7年前关闭。
            
                    
多年来,我想知道为什么类containsIgnoreCase中没有方法String。我们有equalsequalsIgnoreCase,但是只有contains,没有containsIgnoreCase。有什么理由吗?

最佳答案

确切地说出确切原因是不可能的。也许感觉到equals的使用要比contains更为频繁,因此实现equalsIgnoreCase方法将被证明是最有用的,但是实现containsIgnoreCase并不是那么有用。无论如何,很难确定。话虽如此,您确实可以轻松地根据原始的contains方法来实现自己的方法,可以遵循以下方法进行操作:

String s1 = "HeLlO WoRlD";
String s2 = "llo worl";
System.out.println(s1.toLowerCase().contains(s2.toLowerCase()));  // true

10-05 18:27