String的indexof使用

String的indexof使用

String string="abc";
int test=string.indexof("a");
System.out.println(test);

输出结果:0

String string="abc";
int test=string.indexof("d");
System.out.println(test);

输出结果:-1

String string="adbcd";
int test=string.indexof("d",2);
System.out.println(test);

从2位置开始找

输出结果:4

posted @ 2022-01-11 19:32  锦瑟流年3344  阅读(74)  评论(0编辑  收藏  举报