“包含(CharSequence s)” JDK 1.4.2中String类中的方法 [英] "contains(CharSequence s)" method in String class in JDK 1.4.2

查看:155
本文介绍了“包含(CharSequence s)” JDK 1.4.2中String类中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java 1.5,包含(CharSequence s)方法被添加到String类中。此方法

With Java 1.5, the contains(CharSequence s) method was added to the String class. This method


当且仅当此字符串包含指定的char值序列时,返回true。

Returns true if and only if this string contains the specified sequence of char values.

如何在1.5之前的Java版本中执行此操作,特别是在版本1.4.2中?

How would you do this in versions of Java prior to 1.5, specifically in version 1.4.2?

推荐答案

要在Java 1.4中获得与String.contains(substring)相同的效果,您可以使用以下代码段:

To get the same effect as String.contains(substring) in Java 1.4, you can use the following snippet:

String.indexOf(substring) != -1

这篇关于“包含(CharSequence s)” JDK 1.4.2中String类中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆