Sha256: 6f8052defedfb9cf9008affee71c8a7285d7818d17e724a6dbf178c68ea6d62b

Contents?: true

Size: 595 Bytes

Versions: 87

Compression:

Stored size: 595 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("([^A-Za-z0-9']|\\B'|'\\B)", " ");
        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

87 entries across 87 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.97 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.96 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.95 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.94 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.93 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.92 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java