Question from the Java - Fundamentals test

Count the number of words in a string in Java

Medium

Given this code :

public static void main(String[] args) {
        String str = "Chaine de caractĂšre";
        String[] tableau = str.split(" ");
        HashMap<String,Integer> map = new HashMap<String,Integer>();
        for (int i=0; i<tableau.length; i++) {
            if (map.containsKey(tableau[i])) {
                int count = map.get(tableau[i]);
                map.put(tableau[i], count+1);
            }
            else {
                map.put(tableau[i], 1);
            }
        }
        System.out.println(map.size());
    }

What's displayed in the console ?

Author: PierreStatus: PublishedQuestion passed 259 times
Edit
3
Community EvaluationsNo one has reviewed this question yet, be the first!