Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM
- // SOME CLASSES WITHIN A PACKAGE MAY BE RESTRICTED
- // DEFINE ANY CLASS AND METHOD NEEDED
- import java.util.List;
- import java.util.Hashtable;
- // CLASS BEGINS, THIS CLASS IS REQUIRED
- public class Solution
- {
- // METHOD SIGNATURE BEGINS, THIS METHOD IS REQUIRED
- List<String> retrieveMostFrequentlyUsedWords(String literatureText, List<String> wordsToExclude)
- {
- // Replace non-alphnum with space
- String st = literatureText.replaceAll("[^a-zA-Z]", " ");
- // Spilt by space
- String stArr [] = st.Spilt(" ");
- // iterate the array
- Hashtable<String, Integer> counts= new Hashtable<String, Integer>();
- for(int i = 0; i < stArr.size(); i++){
- String word = stArr[i];
- if(counts.get(word) != null){
- count.set(word, count.get(word)++);
- }else{
- count.set(word, 1);
- }
- }
- }
- // METHOD SIGNATURE ENDS
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement