java JDK 1.4.2 中 String 类中的“contains(CharSequence s)”方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1795599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"contains(CharSequence s)" method in String class in JDK 1.4.2
提问by user218420
With Java 1.5, the contains(CharSequence s)method was added to the String class. This method
在 Java 1.5 中,contains(CharSequence s)方法被添加到 String 类中。这个方法
Returns true if and only if this string contains the specified sequence of char values.
当且仅当此字符串包含指定的 char 值序列时才返回 true。
How would you do this in versions of Java prior to 1.5, specifically in version 1.4.2?
在 1.5 之前的 Java 版本中,特别是在 1.4.2 版本中,您将如何执行此操作?
回答by Paul Wagland
To get the same effect as String.contains(substring) in Java 1.4, you can use the following snippet:
要获得与 Java 1.4 中的 String.contains(substring) 相同的效果,您可以使用以下代码段:
String.indexOf(substring) != -1

