当前位置:网站首页>统计字符中每个字符出现的个数
统计字符中每个字符出现的个数
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
边栏推荐
猜你喜欢

ngnix基础知识

Common components of flask

Develop those things: easycvr platform adds playback address authentication function

2022熔化焊接与热切割上岗证题目模拟考试平台操作

PWN攻防世界cgpwn2

300 linear algebra Lecture 4 linear equations

在技术升级中迎合消费者需求,安吉尔净水器“价值战”的竞争之道

杰理之蓝牙耳机品控和生产技巧【篇】

Halcon知识:三维重构的一个尝试

Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)
随机推荐
Test of NSI script
最近公共祖先离线做法(tarjan)
杰理之蓝牙耳机品控和生产技巧【篇】
宅男壁纸大全微信小程序源码-带动态壁纸支持多种流量主
300 linear algebra Lecture 4 linear equations
8K HDR!| Hevc hard solution for chromium - principle / Measurement Guide
目標檢測——Yolo系列
王者战力查询改名工具箱小程序源码-带流量主激励广告
Internship: gradually moving towards project development
寫博客文檔
【Leetcode】最大连续1的个数
编程英语生词笔记本
杰理之、产线装配环节【篇】
Internship: complex JSON format data compilation interface
深度学习 神经网络基础
EMC-电路保护器件-防浪涌及冲击电流用
leetcode刷题:栈与队列03(有效的括号)
How to connect the two nodes of the flow chart
What did you learn about cheating after you went to college?
EURA eurui E1000 series inverter uses PID to realize the relevant parameter setting and wiring of constant pressure water supply function