Java 示例 Word1 的最后一个索引1


Java 示例 Word1 的最后一个索引1

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
   public static void main(String args[]) {
      String candidateString = "This is a Java example.This is another Java example.";
      Pattern p = Pattern.compile("Java");

      Matcher matcher = p.matcher(candidateString);
      matcher.find();
      int nextIndex = matcher.end();

      System.out.print("The last index of Java is:");
      System.out.println(nextIndex);
   }
}