-2

I am try to write a program that will accept a sequence of names in ASCII text files as its only command line argument the files contain English text .the goal is to find 20 most frequently used word across all files ,where each word must appear in at least once time in file we use in java program . Please Suggest me

Thanx in Advance

jrad
  • 3,172
  • 3
  • 22
  • 24
vni
  • 56
  • 5

2 Answers2

1

I would create a map with the key as a word and a counter in the value field.

Map<String, Integer> m = new HashMap<String, Integer>()

Everytime you find a word then check if it is the map (m.containsKey($word)).

If it is not there then add it with value of 1. If it is there then increment the value for that key.

Seems like homework so I think you can figure out the rest...

RNJ
  • 15,272
  • 18
  • 86
  • 131
0

I'd personally start with some kind of WordCount class. This would contain the the word & the number of occurrences it has.

I'd read the files, placing each word into Map, keyed on the word and associated with a WordCount Object.

Once you've read the files, I would take the Map's values & sort it using a Comparator capable of comparing the WordCount Object's count property

This would give me a Collection, sorted in count order

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366