当前位置:网站首页>统计字符中每个字符出现的个数
统计字符中每个字符出现的个数
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
边栏推荐
- [multithreading] realize the singleton mode (hungry and lazy) realize the thread safe singleton mode (double validation lock)
- 天气预报小程序源码 天气类微信小程序源码
- Kuberntes云原生实战一 高可用部署架构
- Oracle deadlock test
- idea中类中显示成员变量和方法
- 新牛牛盲盒微信小程序源码_支持流量变现,带完整素材图片
- 随机头像大全,多分类带历史记录微信小程序源码_支持流量主
- 杰理之烧录上层版物料需要【篇】
- 基于YOLOv5的口罩佩戴检测方法
- 【Opencv450】HOG+SVM 与Hog+cascade进行行人检测
猜你喜欢
杰理之烧录上层版物料需要【篇】
多个张量与多个卷积核做卷积运算的输出结果
在技术升级中迎合消费者需求,安吉尔净水器“价值战”的竞争之道
Error in installing sharp
BC35&BC95 ONENET MQTT(旧)
Data analysts sound tall? Understand these points before you decide whether to transform
【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
深度学习 常见的损失函数
leetcode刷题:栈与队列05(逆波兰表达式求值)
以飞地园区为样本,看雨花与韶山如何奏响长株潭一体化发展高歌
随机推荐
idea中类中显示成员变量和方法
新版图解网络PDF即将发布
2022安全员-B证考试练习题模拟考试平台操作
What did you learn about cheating after you went to college?
股票手机开户哪个app好,安全性较高的
Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
There are four ways to write switch, you know
8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南
leetcode刷题:二叉树02(二叉树的中序遍历)
编程英语生词笔记本
《軟件工程導論(第六版)》 張海藩 複習筆記
Past and present life of product modular design
Error in installing sharp
NIO与传统IO的区别
【级联分类器训练参数】Training Haar Cascades
Simple but modern server dashboard dashdot
On the usage of a magic function
Write blog documents
After adding cocoapods successfully, the header file cannot be imported or an error is reported in not found file
Items in richview documents