Sha256: 2114212d666d7f30c7735ac83014b7f5c5fe01d46c295443d3f801d94745e20b
Contents?: true
Size: 575 Bytes
Versions: 80
Compression:
Stored size: 575 Bytes
Contents
import java.lang.Integer; import java.lang.String; import java.util.HashMap; import java.util.Map; public class WordCount { public Map<String, Integer> phrase( String input ) { Map<String, Integer> countMap = new HashMap<>(); input = input.trim().toLowerCase().replaceAll("[\\W]", " "); final String[] tokenizedInput = input.split("\\s+"); for( String aWord : tokenizedInput ) { Integer count = countMap.get(aWord); countMap.put(aWord, count == null ? 1 : count + 1 ); } return countMap; } }
Version data entries
80 entries across 80 versions & 1 rubygems