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.51 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.50 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.49 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.48 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.47 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.46 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.45 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.44 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.43 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.42 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.41 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.40 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.39 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.38 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.37 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.36 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.35 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.34 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.33 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.32 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java