爪哇 串 lastIndexOf example
lastIndexOf方法可以使用char或string作为参数,也可以提供fromIndex。
方法:
公共int lastIndexOf(int ch)
returns 指数 的 last occurrence 的 字符 与in 串
公共诠释 lastIndexOf(int ch,int 从Index)
returns 指数 的 last occurrence 的 字符 与in 串, going backward 从 specific 指数 “fromIndex”
公共诠释 lastIndexOf(串)
returns 指数 的 last occurrence 的 substring 与in 串
公共诠释 lastIndexOf(int ch,int 从Index)
returns 指数 的 last occurrence 的 substring 与in 串, going backward 从 specific 指数 “fromIndex”
All lastIndexOf 方法s return -1 if 烧焦 要么 substring 是 不 present 在 the 串
串 指数Of Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
包 组织.Arpit.爪哇2blog; 上市 类 串LastIndexOfExample { / * * @作者:Arpit Mandliya */ 上市 静态的 虚空 主要(串 args[]) { 串 力量=“来自java2blog的Hello 世界”; //使用带有字符的lastIndexOf方法 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印(“将lastIndexOf方法与字符一起使用”); 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印(“字符L中的最后一个索引”您好 世界 从 爪哇2blog“是:”+力量.lastIndexOf('l')); 系统.出.打印(); 串 力量1=“从”; 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印(“将lastIndexOf方法与带有字符的fromIndex一起使用”); 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印(“字符o中最后一个从索引6开始的索引”您好 世界 从 爪哇2blog“是:”+力量.lastIndexOf('o',6)); 系统.出.打印(); // 使用 lastIndexOf 方法 与 串 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印("使用 lastIndexOf 方法 与 串"); 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印("持续 指数 的 串 "从在“您好 世界 从 爪哇2blog“是:”+力量.lastIndexOf(力量1)); 系统.出.打印(); 串 怎么做=“你好吗”; 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印("使用 lastIndexOf 方法 与 从Index 与 串"); 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印("持续 指数 的 串 "做“来自“中的索引9怎么样 做 您 做“是:”+怎么做.lastIndexOf(“做”,9)); 系统.出.打印(); 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印("如果 串 要么 烧焦 是 不 有空"); 系统.出.打印(“ ------------------------------------------------ -“); 系统.出.打印(“最后的索引”从在“怎么样 做 您 做“是:”+怎么做.lastIndexOf(“从”)); } } |
当您运行上述程序时,将获得以下输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
---------- -------------------------- 使用 lastIndexOf 方法 与 字符 -------------------------- 持续 指数 的 字符 l 在 “来自java2blog的Hello 世界” 是 : 23 -------------------------- 使用 lastIndexOf 方法 与 从Index 与 字符 -------------------------- 持续 指数 的 字符 o 从 指数 6 在 “来自java2blog的Hello 世界” 是 : 4 -------------------------- 使用 lastIndexOf 方法 与 串 -------------------------- 持续 指数 的 串 “从” 在 “来自java2blog的Hello 世界” 是 : 12 -------------------------- 使用 lastIndexOf 方法 与 从Index 与 串 -------------------------- 持续 指数 的 串 “做” 从 指数 9 在 “你好吗” 是 : 4 -------------------------- 如果 串 要么 烧焦 是 不 有空 -------------------------- 持续 指数 的 “从” 在 “你好吗” 是 : -1 |