Java中字符串中字符的搜索索引
使用该indexOf()方法搜索字符串中字符的索引。
假设以下是我们的字符串。
String myStr = "amit";
现在,让我们找到以上字符串中字符“t”的索引。
strIndex = myStr.indexOf('t');以下是最后一个示例。
示例
public class Demo {
public static void main(String[] args) {
String myStr = "amit";
int strIndex = 0;
System.out.println("String: "+myStr);
//查找字符t的索引
strIndex = myStr.indexOf('t');
System.out.println("Character m found at index: "+strIndex);
}
}输出结果
String: amit Character m found at index: 3
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短