当前位置:网站首页>Count the number of each character in the character
Count the number of each character in the character
2022-07-01 22:11:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Count the number of each character in the character :
import java.util.HashMap;
public class Count the number of each character in the character {
public static void main(String[] args) {
String str = "aaabbbbgbbccc";
char[] ch = str.toCharArray();
HashMap<Character,Integer> hm = new HashMap<>();
for (char c : ch) {
// If it contains this character, it is the number +1
if (hm.containsKey(c)) {
hm.put(c,hm.get(c) + 1);
}else {
hm.put(c, 1);
}
}
System.out.println(hm);
}
}Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/147189.html Link to the original text :https://javaforall.cn
边栏推荐
猜你喜欢
随机推荐
JS how to get a list of elements in a collection object
从20s优化到500ms,我用了这三招
Significance and measures of security encryption of industrial control equipment
新版图解网络PDF即将发布
php反射型xss,反射型XSS测试及修复
基于LSTM模型实现新闻分类
[STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
The difference between NiO and traditional IO
浏览器tab页之间的通信
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
MQ学习笔记
One of the basic learning of function
Pytest Collection (2) - mode de fonctionnement pytest
MySQL empties table data
能升职加薪?PMP证书含金量浅析
A debugging to understand the slot mechanism of redis cluster
MySQL数据库驱动(JDBC Driver)jar包下载
Aidl basic use
物联网rfid等
vscode的使用









