小白教程
所有教程
关于
Search
172.70.178.72
172.70.178.72
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Java string lastindexof”的源代码
本页内容
上一节:
Java_string_intern
下一节:
Java_string_length
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:int lastIndexOf(String str, int fromIndex)}}[[Category:java string|24]] = Java lastIndexOf() 方法 = [[java string|Java String类]] lastIndexOf() 方法有以下四种形式: * '''public int lastIndexOf(int ch):''' 返回指定字符在此字符串中最后一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。 * '''public int lastIndexOf(int ch, int fromIndex):''' 返回指定字符在此字符串中最后一次出现处的索引,从指定的索引处开始进行反向搜索,如果此字符串中没有这样的字符,则返回 -1。 * '''public int lastIndexOf(String str):''' 返回指定子字符串在此字符串中最右边出现处的索引,如果此字符串中没有这样的字符,则返回 -1。 * '''public int lastIndexOf(String str, int fromIndex):''' 返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索,如果此字符串中没有这样的字符,则返回 -1。 === 语法 === <pre> public int lastIndexOf(int ch) 或 public int lastIndexOf(int ch, int fromIndex) 或 public int lastIndexOf(String str) 或 public int lastIndexOf(String str, int fromIndex) </pre> === 参数 === * '''ch''' -- 字符。 * '''fromIndex''' -- 开始搜索的索引位置。 * '''str''' -- 要搜索的子字符串。 === 返回值 === 指定子字符串在字符串中第一次出现处的索引值。 == <pre> public class Test { public static void main(String args[]) { String Str = new String("小白教程:www.xiaobai.wang"); String SubStr1 = new String("xiaobai"); String SubStr2 = new String("com"); System.out.print("查找字符 o 最后出现的位置 :" ); System.out.println(Str.lastIndexOf( 'o' )); System.out.print("从第14个位置查找字符 o 最后出现的位置 :" ); System.out.println(Str.lastIndexOf( 'o', 14 )); System.out.print("子字符串 SubStr1 最后出现的位置:" ); System.out.println( Str.lastIndexOf( SubStr1 )); System.out.print("从第十五个位置开始搜索子字符串 SubStr1最后出现的位置 :" ); System.out.println( Str.lastIndexOf( SubStr1, 15 )); System.out.print("子字符串 SubStr2 最后出现的位置 :" ); System.out.println(Str.lastIndexOf( SubStr2 )); } } </pre> 以上程序执行结果为: <pre> 查找字符 o 最后出现的位置 :17 从第14个位置查找字符 o 最后出现的位置 :13 子字符串 SubStr1 最后出现的位置:9 从第十五个位置开始搜索子字符串 SubStr1最后出现的位置 :9 子字符串 SubStr2 最后出现的位置 :16 </pre> [[java string|Java String类]]
返回至“
Java string lastindexof
”。
上一节:
Java_string_intern
下一节:
Java_string_length