Java 实例 - 查找字符串最后一次出现的位置

Java 教程 · 2019-02-10 06:44:37

以下实例中我们通过字符串函数 strOrig.lastIndexOf(Stringname) 来查找子字符串 Stringname 在 strOrig 出现的位置:

实例代码如下:

SearchlastString.java 文件

public class SearchlastString { public static void main(String[] args) { String strOrig = "Hello world ,Hello Codercto"; int lastIndex = strOrig.lastIndexOf("Codercto"); if(lastIndex == - 1){ System.out.println("没有找到字符串 Codercto"); }else{ System.out.println("Codercto 字符串最后出现的位置: "+ lastIndex); } } }

以上代码实例输出结果为:

Codercto 字符串最后出现的位置: 19

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

Professional JavaScript for Web Developers

Professional JavaScript for Web Developers

Nicholas C. Zakas / Wrox / 2009-1-14 / USD 49.99

This eagerly anticipated update to the breakout book on JavaScript offers you an in-depth look at the numerous advances to the techniques and technology of the JavaScript language. You'll see why Java......一起来看看 《Professional JavaScript for Web Developers》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具