韩俊的个人博客

一个不喜欢当程序员的人写的博客

获取每个单词出现的频率
package play;

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

public class 每个单词出现的频率 {
	public static void main(String[] args) {
		String s = "Welcome to ADempiere, a commons-based peer-production of Open Source ERP Applications. This Wiki is for the global community to contribute and share know-how and domain expertise. We hope you can find as much open information and participate in making it most usable for everyone. This project has a bazaar of Citizens with a Community Council Team which work in theFunctional Team and Technical Team along the Software Development Procedure supported and funded by the foundation ADempiere e.V..";
		String s_sub = s.replace(", ", " ").replace(". ", " ");//删除符号,单词之间用空格间隔
		String sArr[] = s_sub.split(" ");//只要能把需要分割的东西分割成数组就行了,按实际情况处理
		Map<String, Integer> m = new HashMap<String, Integer>();
		for (int i = 0; i < sArr.length; i++) {
			String danCi = sArr[i];
			if (m.get(danCi) == null) {
				m.put(danCi, 1);
			}
			else {
				m.put(danCi, m.get(danCi) + 1);
			}
		}
		for (Entry<String, Integer> entry : m.entrySet()) {
			System.out.println(entry.getKey() + "\t次数" + entry.getValue());
		}
	}
}
以上。
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hjgzj/article/details/51553433
个人分类: java 积累篇
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

获取每个单词出现的频率

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭