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.71 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.70 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.69 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.68 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.67 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.66 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.65 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.64 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.63 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.62 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.61 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.60 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.59 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.58 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.57 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.56 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.55 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.54 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.53 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java
trackler-2.2.1.52 tracks/java/exercises/word-count/.meta/src/reference/java/WordCount.java