在 Java 中搜索字符串中的字符。
可以使用 String 类的 indexOf() 方法在字符串中搜索特定字母。如果找到该词,此方法将返回字符串中该词的位置索引。否则它将返回 -1。
示例
public class Test {
public static void main(String args[]) {
String str = new String("hi welcome to Tutorialspoint");
int index = str.indexOf('w');
System.out.println("Index of the letter w :: "+index);
}
}输出
Index of the letter w :: 3
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP