java中怎么判断一个字符串中包含某个字符或字符串

如题所述

第1个回答  推荐于2018-03-01
/**
* Returns true if and only if this string contains the specified
* sequence of char values.
*
* @param s the sequence to search for
* @return true if this string contains <code>s</code>, false otherwise
* @throws NullPointerException if <code>s</code> is <code>null</code>
* @since 1.5
*/
public boolean contains(CharSequence s) {
return indexOf(s.toString()) > -1;
}

String str = "dfdf点点滴滴";
boolean b1 = str.contains("d");
boolean b2 = str.contains("点点滴滴");本回答被提问者和网友采纳
第2个回答  2016-10-21
可以用String.indexOf();不包含的话返回-1
第3个回答  2016-10-21
用isContain 函数
第4个回答  2017-10-13
str.indexOf("");
相似回答