Java中判断字符串中相同字符的个数

  1. public static int countStr(String str1, String str2) {   
  2.         int counter=0;  
  3.         if (str1.indexOf(str2) == -1) {    
  4.             return 0;  
  5.         }   
  6.             while(str1.indexOf(str2)!=-1){  
  7.                 counter++;  
  8.                 str1=str1.substring(str1.indexOf(str2)+str2.length());  
  9.             }  
  10.             return counter;    
  11.     }   
原文地址:https://www.cnblogs.com/yanduanduan/p/4884697.html