Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. // IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM
  2. // SOME CLASSES WITHIN A PACKAGE MAY BE RESTRICTED
  3. // DEFINE ANY CLASS AND METHOD NEEDED
  4. import java.util.List;
  5. import java.util.Hashtable;
  6.  
  7. // CLASS BEGINS, THIS CLASS IS REQUIRED
  8. public class Solution
  9. {
  10. // METHOD SIGNATURE BEGINS, THIS METHOD IS REQUIRED
  11. List<String> retrieveMostFrequentlyUsedWords(String literatureText, List<String> wordsToExclude)
  12. {
  13. // Replace non-alphnum with space
  14. String st = literatureText.replaceAll("[^a-zA-Z]", " ");
  15. // Spilt by space
  16. String stArr [] = st.Spilt(" ");
  17. // iterate the array
  18. Hashtable<String, Integer> counts= new Hashtable<String, Integer>();
  19. for(int i = 0; i < stArr.size(); i++){
  20. String word = stArr[i];
  21. if(counts.get(word) != null){
  22. count.set(word, count.get(word)++);
  23. }else{
  24. count.set(word, 1);
  25. }
  26. }
  27.  
  28. }
  29. // METHOD SIGNATURE ENDS
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement