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

Version Path
trackler-2.2.1.91 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.90 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.89 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.88 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.87 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.86 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.85 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.84 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.83 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.82 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.81 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.80 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.79 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.78 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.77 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.76 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.75 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.74 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.73 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.72 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java