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.180 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.179 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.178 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.177 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.176 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.175 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.174 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.173 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.172 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.171 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.170 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.169 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.167 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.166 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.165 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.164 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.163 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.162 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.161 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.160 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java