在Java中搜索字符串中的字符。

您可以使用String类的indexOf()方法在字符串中搜索特定字母。此方法返回字符串中单词的位置索引(如果找到)。否则返回-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