Home > Java > javaTutorial > Java Example - Find the last occurrence of a string

Java Example - Find the last occurrence of a string

黄舟
Release: 2017-02-21 09:58:30
Original
2348 people have browsed it

In the following example, we use the string function strOrig.lastIndexOf(Stringname) to find the position where the substring Stringname appears in strOrig:

The example code is as follows:

//SearchlastString.java 文件public class SearchlastString {
   public static void main(String[] args) {
      String strOrig = "Hello world ,Hello Reader";
      int lastIndex = strOrig.lastIndexOf("Hello");
      if(lastIndex == - 1){
         System.out.println("Hello not found");
      }else{
         System.out.println("Last occurrence of Hello
         is at index "+ lastIndex);
      }
   }}
Copy after login

Above The output result of the code example is:

Last occurrence of Hello is at index 13
Copy after login

The above is the Java example - find the content of the last occurrence of a string, please pay attention to more related content PHP Chinese website (www.php.cn)!



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template