java字符串统计出现次数 java如何统计字符串中每个字符出现的次数?

java如何统计字符串中每个字符出现的次数?Public class test{Public static void main(string[]args){//指定字符和字符串char c=“1”st

java如何统计字符串中每个字符出现的次数?

Public class test{Public static void main(string[]args){//指定字符和字符串char c=“1”string string=“123456789111”系统输出打印(getCharCount(c,string))}公共静态int getCharCount(char c,string string){int count=0 for(int i=0 i<)字符串长度(一){字符温度=字符串.charAt(i) If(C==temp)count}return count}

首先将字符串拆分为一个数组,然后使用map<string、int>对数字进行计数,然后打印