Java示例字符串中特定单词的最后索引


Java示例字符串中特定单词的最后索引

import java.util.regex.Matcher;

import java.util.regex.Pattern;



public class Main {

   public static void main(String args[]) {

      String s1 = "Sairamkrishna Mammahe,codingdict india Pvt Ltd.";

      Pattern p1 = Pattern.compile("codingdict");



      Matcher m1 = p1.matcher(s1);

      m1.find();

      int nextIndex = m1.end();



      System.out.print("The last index is:");

      System.out.println(nextIndex);

   }

}