1、获取字符串长度:使用String类的length()方法
![](https://i-blog.csdnimg.cn/blog_migrate/216726eaa48b016cfbdd8d653a757fdb.png)
2、查找字符串:indexOf()方法和lastIndexOf()方法。
2.1、indexOf()方法用于查找字符、字符串在指定字符串第一次出现的索引位置;
2.2、lastIndexOf()方法用于查找字符、字符串在指定字符串第一次出现的索引位置;
![](https://i-blog.csdnimg.cn/blog_migrate/a0ee85d46e23096598b77de23fe36e5f.png)
当str.lastIndexOf(" ")时,即参数为空字符串时,返回结果等价于str.length
![](https://i-blog.csdnimg.cn/blog_migrate/a8f529ab17627ed0a8d190e89853bf90.png)
3、获取指定索引位置的字符
![](https://i-blog.csdnimg.cn/blog_migrate/a9afbf2986fbf033e94d5e478bc3e652.png)
4、训练:获取任意字符串最中间的字符(如果字符串长度为偶数,则返回索引小的最中间的字符)
![](https://i-blog.csdnimg.cn/blog_migrate/9b00306d3a123a58ed7bf2c1272547ca.png)