Pattern pattern = Pattern.compile("[a-zA-Z']+"); Matcher matcher = pattern.matcher(sb); Map<String, Integer> map = new HashMap<String, Integer>(); String word = ""; Integer num = null; int total = 0;
while(matcher.find()) { word = matcher.group(); total ++; if(map.containsKey(word)) { num = map.get(word); num += 1; } else { num = 1; } map.put(word, num); }