Java String contains() 方法示例。
String 类的 contains() 方法当且仅当该字符串包含指定序列的 char 值时返回 true。
示例
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str1 = "tutorials point", str2 = "http://";
CharSequence cs1 = "int";
//string contains the specified sequence of char values
boolean retval = str1.contains(cs1);
System.out.println("Method returns : " + retval);
//string does not contain the specified sequence of char value
retval = str2.contains("_");
System.out.println("Methods returns: " + retval);
}
}输出
Method returns : true Methods returns: false
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP