Chinaunix首页 | 论坛 | 博客
  • 博客访问: 104543
  • 博文数量: 41
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 352
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-23 12:37
文章分类

全部博文(41)

文章存档

2015年(1)

2014年(28)

2013年(12)

我的朋友

分类: Java

2014-08-31 09:39:34


点击(此处)折叠或打开

  1. import java.util.HashMap;
  2. import java.util.Map.Entry;

  3. public class WordCount {
  4.     public static void main(String[] args){
  5.         
  6.     String content = "我爱中国aabb我爱中国1111CCC";
  7.     HashMap<Character,Integer> map = new HashMap<Character,Integer>();
  8.     for(int i=0;i<content.length();i++)
  9.     {
  10.     char c =content.charAt(i);
  11.     
  12.     Integer num =(Integer)map.get(c);
  13.     
  14.      if(num == null)
  15.      num = 1;
  16.      else
  17.      num = num +1;
  18.      map.put(c,num);
  19.     }
  20.     
  21.     for(Entry<Character,Integer> entry : map.entrySet())
  22.     {
  23.      System.out.println(entry.getKey()+ ":" + entry.getValue());
  24.     }
  25.  }    
  26.     
  27. }



阅读(987) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~