Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- General Idea:
- sentence: input string as an array of words (split by space)
- arraylist: your arraylist of words (your custom class)
- foreach string in sentence:
- found = false
- foreach word in arraylist:
- if word equals word:
- word.count++
- found = true
- break
- if !found
- arraylist.add(word)
- My Code:
- String[] sProc = input.trim().split(" ");
- for (int i = 0; i < sProc.length; i++) {
- boolean found = false;
- loop: for (int j = 0; j < strCount.size(); j++)
- if (sProc[i].equals(strCount.get(j).getString())) {
- strCount.get(j).inc();
- found = true;
- break loop;
- }
- if (!found)
- strCount.add(new StrCount(sProc[i]));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement