当前位置:网站首页>统计字符中每个字符出现的个数
统计字符中每个字符出现的个数
2022-07-01 20:21:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
统计字符中每个字符出现的个数:
import java.util.HashMap;
public class 统计字符中每个字符出现的个数 {
public static void main(String[] args) {
String str = "aaabbbbgbbccc";
char[] ch = str.toCharArray();
HashMap<Character,Integer> hm = new HashMap<>();
for (char c : ch) {
//如果是包含这个字符就个数+1
if (hm.containsKey(c)) {
hm.put(c,hm.get(c) + 1);
}else {
hm.put(c, 1);
}
}
System.out.println(hm);
}
}发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/147189.html原文链接:https://javaforall.cn
边栏推荐
猜你喜欢
随机推荐
4. 对象映射 - Mapping.Mapstercover
【let var const】
Niuke programming question -- must brush the string of 101 (brush the question efficiently, draw inferences from one instance)
How to connect the two nodes of the flow chart
NIO与传统IO的区别
极客DIY开源方案分享——数字幅频均衡功率放大器设计(实用的嵌入式电子设计作品软硬件综合实践)
UVM教程
Entering Ruxin Town, digital intelligence transformation connects "future community"
Myslq ten kinds of locks, an article will take you to fully analyze
一次调试去了解redis集群的slot机制
On the next generation entrance of the metauniverse -- the implementation of brain computer interface
架构师毕业总结
internship:复杂json格式数据编写接口
Detailed explanation and code example of affinity propagation clustering calculation formula based on graph
Oracle deadlock test
leetcode刷题:二叉树02(二叉树的中序遍历)
EDA工具对芯片产业的重要性知识科普
杰理之烧录上层版物料需要【篇】
PHP gets the external chain address of wechat applet and applet store
【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程









