您可以使用indexOf()String类的方法在字符串中搜索特定字母。此方法返回字符串中单词的位置索引(如果找到)。否则返回-1。
public class Test {
public static void main(String args[]){
String str = new String("hi welcome to Nhooo");
int index = str.indexOf('w');
System.out.println("Index of the letter w :: "+index);
}
}Index of the letter w :: 3