首页 > 其他 > 详细

统计字符串中每个字母出现的次数

时间:2020-03-11 17:06:19      阅读:86      评论:0      收藏:0      [点我收藏+]
	public void count(String string) {
		char[] c=string.toCharArray();
		Map<Character, Integer> map=new HashMap<Character, Integer>();
		for(int i=0;i<c.length;i++) {
			if(map.containsKey(c[i])) {
				map.put(c[i], map.get(c[i])+1);
			}else {
				map.put(c[i],1);
			}
		}
		for(Character character:map.keySet()) {
			System.out.println(character+":"+map.get(character));
		}

	}

  

统计字符串中每个字母出现的次数

原文:https://www.cnblogs.com/saifei1125/p/12462947.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!