public static void main(String[] args) {
String a = "hello";
int indexOf = a.indexOf("h");
if (indexOf == -1) {
System.out.println("没有字母h");
}else {
System.out.println("有字母h");
}
}
可以参考以上代码。
public String check(String str, char x){
char[] cs =str.getChars();
String rel = ““;
for(char c : cs){
if(c ==x){
rel += "有"+x+"\r\n";
}
}
return rel;
}