- public static void main(String[] args) {
- TreeMap<Character,Integer> map=new TreeMap<Character,Integer>();
- String str="asdfasdf";
- Integer count=0;
- for (char c:str.toCharArray())
- {
- count=map.get(c);
- if(count==null)
- count=0;
- map.put(c, ++count);
- }
- Set<Map.Entry<Character,Integer>> entry=map.entrySet();
- for(Map.Entry<Character,Integer> e:entry)
- {
- System.out.print(e.getKey()+"("+e.getValue()+"次) " );
- }
-
- }
复制代码 参考下.
|