import java.util.regex.Matcher;  
import java.util.regex.Pattern;  
  
  
public class Demo {  
  
    //判断"Ab2Ad3A4"中"A"出现第二次的位置  
    public static void main(String[] args) {  
        String str = "Ab2Ad3A4";  
        Pattern pattern = Pattern.compile("A");  
        Matcher findMatcher = pattern.matcher(str);  
        int number = 0;  
        while(findMatcher.find()) {  
            number++;  
           if(number == 2){//当“A”第二次出现时停止  
              break;  
           }  
        }  
        int i = findMatcher.start();//“A”第二次出现的位置  
        System.out.println("'A'第二次出现的位置是:"+i);  
    }  
      
}  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2021-12-20
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案