import java.util.*;
class TreeMapTest
{
public static void main(String[] args)
{
TreeMap t=count("abdbshsguwdihwe");
System.out.println(t);
}
public static TreeMap count(String str)
{
char[] arr=str.toCharArray();
int count=0;
TreeMap<Character,Integer> tree=new TreeMap<Character,Integer>();
for(int x=0;x<arr.length;x++)
{
Integer value=tree.get(arr[x]);
if(null!=value)
count=value;
count++;
tree.put(arr[x],count);
count=0;
}
return tree;
}
}
使用TreeMap计算字符串中每个字母出现的次数
最新推荐文章于 2021-10-15 13:25:16 发布