- public static void main(String[] args) {
- // TODO Auto-generated method stub
- StringBuffer s1 = new StringBuffer("abcdefghijijiji");
- TreeMap<Character,Integer> m = new TreeMap<Character,Integer>();
- m.put('a', 0);
- m.put('b', 0);
- m.put('c', 0);
- m.put('d', 0);
- m.put('e', 0);
- m.put('f', 0);
- m.put('g', 0);
- m.put('h', 0);
- m.put('i', 0);
- m.put('j', 0);
- Set s = m.keySet();
- for (int i = 0; i < s1.length(); i++) {
- char ch = s1.charAt(i);
- int n = m.get(ch) + 1;
- m.put(ch, n);
- }
- Object[] ch = s.toArray();
- for (int i = 0; i < ch.length; i++) {
- System.out.print(ch[i] + ":" + m.get(ch[i]));
- if(i < ch.length-1){
- System.out.print(", ");
- }
- }
- System.out.println();
- }
- //该片段来自于http://www.codesnippet.cn/detail/300520133685.html
来源: http://www.codesnippet.cn/detail/300520133685.html