java统计一段英文中单词及个数
2017-10-19 23:01
267 查看
public static void countWords(String str){ Map<String, Integer> map=new HashMap<String, Integer>(); Pattern p=Pattern.compile("\\b[a-zA-Z-]+\\b");//正则表达式 Matcher m=p.matcher(str); while(m.find()){ String mstr=m.group(); if(map.containsKey(mstr)){ map.put(mstr,map.get(mstr)+1); }else{ map.put(mstr, 1); } } Set<Entry<String, Integer>> entrySet = map.entrySet(); Iterator<Entry<String,Integer>> it=entrySet.iterator(); while(it.hasNext()){ Entry<String, Integer> next = it.next(); System.out.println(next.getKey()+" 个数:"+next.getValue()); } }
相关文章推荐
- Java 读取一段英文文档统计每个单词出现的次数和单词的总数
- Java 读取一段英文文档统计每个单词出现的次数和单词的总数
- JavaScript中模拟java的map键值统计一段英文中各个单词出现的次数
- Java读取文本文件中一段英文统计单词个数
- 使用Java统计英文文章的单词频率。
- Java统计英文句子中出现次数最多的单词并计算出现次数的方法
- JAVA-统计英文句子中出现次数最多的单词和出现的次数
- java编程题:输入一段英文,获取每个单词出现的次数跟位置,并排序
- 统计一段英文每个单词出现的次数
- F# 统计一段英文文章中不同单词出现的次数
- java实现读取一篇英文文章,统计其中每个单词出现的次数并排序输出
- Java统计一篇英文单词出现次数
- 实现一个控制台程序,给定一段英文字符串,统计其中各个英文单词(4字符以上含4字符)的出现频率。
- 转:java写一个方法实现统计一条英文语句忠每个单词的个数
- 一个利用map统计一段英文文章中每个单词出现次数的小程序
- 给出一段英文,统计单词出现的次数
- 统计一段英文中单词出现的次数
- Java统计一段文字多少重复次数最多单词
- java-统计一段句子中各单词出现的次数
- (转)F# 统计一段英文文章中不同单词出现的次数