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.159 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.158 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.157 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.156 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.155 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.154 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.153 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.152 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.151 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.150 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.149 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.148 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.147 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.146 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.145 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.144 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.143 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.142 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.141 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.140 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java