01.代码如下:
package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public static void main(String args[]) { String str = "helloworld"; // 实例化字符串对象 System.out.println(str.indexOf("world")); // 返回满足条件单词的第一个字母的索引 System.out.println(str.indexOf("l")); // 返回的是第一个查找到的子字符串位置 System.out.println(str.indexOf("l", 5)); // 从第6个元素开始查找子字符串位置 System.out.println(str.lastIndexOf("l")); // 从后向前开始查找指定字符串的位置 } }
02.效果如下:
知识有价,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢。