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.31 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.30 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.29 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.28 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.27 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.26 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.25 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.24 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.23 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.22 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.21 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.20 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.19 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.18 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.17 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.16 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.15 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.14 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.13 tracks/java/exercises/word-count/src/example/java/WordCount.java
trackler-2.2.1.12 tracks/java/exercises/word-count/src/example/java/WordCount.java