Guest User

Untitled

a guest
Jun 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. public class TextParser {
  5.  
  6. public Map<String, Integer> parseTextWordCount(String text) {
  7. HashMap<String, Integer> result = new HashMap<String, Integer>();
  8. if(text != null)
  9. {
  10. if(!text.trim().isEmpty())
  11. {
  12. String[] words = text.split(" ");
  13. for (String word : words) {
  14. word = word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase();
  15. if(result.containsKey(word))
  16. result.put(word, result.get(word)+1);
  17. else
  18. result.put(word, 1);
  19. }
  20. }
  21. }
  22. return result;
  23. }
  24.  
  25. }
Add Comment
Please, Sign In to add comment