当前位置:网站首页>统计字符中每个字符出现的个数
统计字符中每个字符出现的个数
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
边栏推荐
- Items in richview documents
- 打出三位数的所有水仙花数「建议收藏」
- Practical project notes (I) -- creation of virtual machine
- 关联线探究,如何连接流程图的两个节点
- 寫博客文檔
- 一次调试去了解redis集群的slot机制
- leetcode刷题:栈与队列07(滑动窗口最大值)
- Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)
- Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
- 图片拼图微信小程序源码_支持多模板制作和流量主
猜你喜欢
随机推荐
极客DIY开源方案分享——数字幅频均衡功率放大器设计(实用的嵌入式电子设计作品软硬件综合实践)
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
联想电脑怎么连接蓝牙耳机?
8K HDR!| Hevc hard solution for chromium - principle / Measurement Guide
图片拼图微信小程序源码_支持多模板制作和流量主
Is it safe to open an account online? Can a novice open a stock trading account.
【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
leetcode刷题:栈与队列03(有效的括号)
深度学习 神经网络基础
Using qeventloop to realize synchronous waiting for the return of slot function
杰理之、产线装配环节【篇】
leetcode刷题:二叉树02(二叉树的中序遍历)
基于YOLOv5的口罩佩戴检测方法
Richview RichEdit srichviewedit PageSize page setup and synchronization
个人炒股怎样开户?安全吗。
Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)
PHP 读取ini或env类型配置
Customize the insertion of page labels and realize the initial search of similar address books
功利点没啥!
On the next generation entrance of the metauniverse -- the implementation of brain computer interface