关闭

获取每个单词出现的频率

标签: java获取每个单词出现次数
269人阅读 评论(0) 收藏 举报
分类:
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());
		}
	}
}
以上。
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:19396次
    • 积分:475
    • 等级:
    • 排名:千里之外
    • 原创:26篇
    • 转载:3篇
    • 译文:0篇
    • 评论:11条
    最新评论