比如String a="acacacwerwac";
String b="ac";
显示四
String b="ac";
显示四
解决方案 »
- 手上有个题目不是很理解,请各位大侠们指导下~!!!
- java 中 开发一个音乐播放器 怎么实现歌词显示同步
- 页面的加了这个上传的enctype="multipart/form-data,怎么取字段的数组值,不能request.getParameterValues(""),急!!!
- 初学JAVA,一个SERVLET问题,请大家来看看~
- JAVA是否需要数据库
- 新手上路:能多个组件共用一个事件适配器嘛?
- 问题:repaint()重绘时原字符不消失
- 今天83%通过JP的感想
- Forte(tm) for Java(tm),release 2.0,Community Edition (Build 1160)是什么
- 再一个字符串中如何表示一个回车符
- java写的小程序如何打包成可执行文件?
- java.sql.SQLException: 第 1 行: 't_update' 附近有语法错误。
这样 while (a.contains(b)) {
a = a.replaceFirst("ac", "");
count++;
} System.out.println(count);
int count = 0;
while (a.contains(b)) {
a = a.replaceFirst(b, "");
count++;
} System.out.println(count);
String a = "acacacwerwac";
String b = "ac";
int i = 0;
Pattern p = Pattern.compile(b);
Matcher m = p.matcher(a);
while(m.find()){
i++;
}
System.out.println(i);
String a = "acacacwerwac";
String b = "ac";
int count = count(a, b);
System.out.println(count);
}
private static int count(String src, String find) {
int count = 0;
int index = src.indexOf(find);
while(index > -1) {
count++;
index = src.indexOf(find, index + 1);
}
return count;
}
}
int count = 0;
int index = src.indexOf(find);
int len = find.length();
while(index > -1) {
count++;
index = src.indexOf(find, index + len);
}
return count;
}