/**
* @author TANGSHUAI
* @date 2021年3月15日 上午10:37:10
* 一段文本,如何统计字符串出现的个数
*/
public class TestMap {
public static void main(String[] args) {
String str="张三李三王三";
System.out.println(str.length());
Map<String, Integer> map=new HashMap<>();
for (int i = 0; i < str.length(); i++) {
char charAt = str.charAt(i);
String c=new String (new char[] {charAt});
if(map.containsKey(c)) {
Integer integer = map.get(c);
map.replace(c, integer+1);
}else {
map.put(c, 1);
}
}
System.out.println(map.toString());
}
}
3.一段文本,如何统计字符串出现的个数
最新推荐文章于 2022-10-24 20:05:06 发布