-3

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?

I appreciate your reply!

Carol.Kar
  • 4,581
  • 36
  • 131
  • 264
  • Well, if you simply want frequency of each word, put the words in a *collection* and call `Collections.frequency()` – TheLostMind Sep 10 '14 at 07:18

1 Answers1

3

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));
Vahid
  • 137
  • 8