当前位置:网站首页>统计字符中每个字符出现的个数
统计字符中每个字符出现的个数
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
边栏推荐
- 杰理之关于长按开机检测抬起问题【篇】
- EDA工具对芯片产业的重要性知识科普
- On the next generation entrance of the metauniverse -- the implementation of brain computer interface
- 宅男壁纸大全微信小程序源码-带动态壁纸支持多种流量主
-
- Big factories are wolves, small factories are dogs?
- Test of NSI script
- Architect graduation summary
- EMC-电路保护器件-防浪涌及冲击电流用
- Simple but modern server dashboard dashdot
猜你喜欢

薛定谔的日语学习小程序源码

On the next generation entrance of the metauniverse -- the implementation of brain computer interface

最近公共祖先离线做法(tarjan)

Customize the insertion of page labels and realize the initial search of similar address books

Richview trvdocparameters page parameter settings

latex如何打空格

随机头像大全,多分类带历史记录微信小程序源码_支持流量主

目標檢測——Yolo系列

Big factories are wolves, small factories are dogs?

Learn white box test case design from simple to deep
随机推荐
能升职加薪?PMP证书含金量浅析
安装mysql时出现:需要这两个包perl(Data::Dumper),perl(JSON)
Items in richview documents
Spark面试题
杰理之关于长按开机检测抬起问题【篇】
Principle of motion capture system
idea中类中显示成员变量和方法
2022年高处安装、维护、拆除考题模拟考试平台操作
宅男壁纸大全微信小程序源码-带动态壁纸支持多种流量主
How to connect the two nodes of the flow chart
GCC编译
How to create a pyramid with openmesh
Customize the insertion of page labels and realize the initial search of similar address books
Comprehensive evaluation and detailed inventory of high-quality note taking software (I) note, obsedian, remnote, flowus
Iframe parent-child page communication
十三届蓝桥杯B组国赛
以飞地园区为样本,看雨花与韶山如何奏响长株潭一体化发展高歌
考虑关系的图卷积神经网络R-GCN的一些理解以及DGL官方代码的一些讲解
升级版手机检测微信工具小程序源码-支持多种流量主模式