一个字符串在另一个字符串中出现的次数
public static int getStringAppearTimers(String target, String token) { int times = 0; for (String tmp = target; tmp != null && tmp.length() >= token.length(); ) { if(tmp.indexOf(token) == 0) { times ++; tmp = tmp.substring(token.length()); } else { tmp = tmp.substring(1); } } return times; }
这里提供了一个方法,有很多方法,这个方法也有改进之处。