单词频率分布单词、频率

由网友(孤傲)分享简介:我看了两个TXT文件的话。I have read in two txt files with words.现在我想知道如何计算这两个字符串的频率分布。我的想法是把它们放进一个数组,并将它们分割; 。然而,如何计算出的频率分布?Now I was wondering how to calculate the fre...

我看了两个TXT文件的话。

I have read in two txt files with words.

现在我想知道如何计算这两个字符串的频率分布。我的想法是把它们放进一个数组,并将它们分割; 。然而,如何计算出的频率分布?

Now I was wondering how to calculate the frequency distribution of these two Strings. My idea is to put them into an array and split them by ;. However, how to calculated the frequency distribution?

我AP preciate您的答复!

I appreciate your reply!

推荐答案

样品code是这样的:

Sample code is something like this:

    String str1 = "java;python;javascript;programming;Hello;World;Hello";
    String str2 = "java;python;javascript;programming;Hello;World;Hello";

    List<String> list = new ArrayList<String>();
    list.addAll(Arrays.asList(str1.split(";")));
    list.addAll(Arrays.asList(str2.split(";")));

    for (String word : list) 
        System.out.println(word + " --> " + Collections.frequency(list,word));
阅读全文

相关推荐

最新文章