java判断字符串是否包含某个字符串 java判断字符串是否包含
转载
public static boolean method1(String input, String seek) {
//消息提醒
System.out.println("限制输入类型为String类型字符串");
//输出原字符串内容
System.out.println("原字符串: " + input);
//用于计数
int count = 0;
//遍历字符串
for (int i = 0; i < input.length(); i++) {
//count用于计算字符串的字符数量
count++;
}
//将seek 赋值到 seek1
String seek1 = seek;
//indexOf 为java自带
int a = input.indexOf(seek1);
//
System.out.println("字符串共" + count + "个");
//设置初始返回值为false
boolean b = false;
//用于做判断 a != 1
if (a != 1) {
System.out.println("输入的字符串中包含: “" + seek + "” 这个内容");
b = true;
System.out.println(b);
} else {
System.out.println("输入的字符串中不包含: " + seek + " 这个内容");
b = false;
}
return b;
}
public static void main(String[] args) {
method1("哈哈哈哈哈哈哈哈哈是", "是");
}
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。