java中判断一串字符串是否含有字符
展开全部
public class IndexOfTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "I love china,my motherland!";
int result1 = str.indexOf("china");
int result2 = str.indexOf("chinese");
if(result1 != -1){
System.out.println("字符串str中包含子串“china”"+result1);
}else{
System.out.println("字符串str中不包含子串“china”"+result1);
}
if(result2 != -1){
System.out.println("字符串str中包含子串“chinese”"+result2);
}else{
System.out.println("字符串str中不包含子串“chinese”"+result2);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "I love china,my motherland!";
int result1 = str.indexOf("china");
int result2 = str.indexOf("chinese");
if(result1 != -1){
System.out.println("字符串str中包含子串“china”"+result1);
}else{
System.out.println("字符串str中不包含子串“china”"+result1);
}
if(result2 != -1){
System.out.println("字符串str中包含子串“chinese”"+result2);
}else{
System.out.println("字符串str中不包含子串“chinese”"+result2);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询