Question: I was wondering how would I fix my code so that my output would be correct. I only can edit a specific section of my code. Thank you very much

This is my code

```
import java.util.HashMap;

public class OccurenceChecker {
    public static void main(String[] args) 
    { 

        //CANT BE FIXED
        String phrase = "Good Morning. Welcome to my store. My store is a grocery store.";

        HashMap<String, Integer> map = new HashMap<String, Integer>();
        String[] ignored = phrase.split("\n\t\r(){},:;!?.[]");

        //CAN BE FIX THIS POINT ON.
        for (String ignore : ignored) 
        {
            Integer count = map.get(ignore);
            if (count == null) 
            {
                count = 0;
            }
            map.put(ignore, count + 1);
        }

        for (int i = 0; i< ignored.length; i++)
        {
            System.out.println(ignored[i]);
        }
        System.out.println(map);
    }
}

```

EXPECTED OUTPUT

```
{a=1, Morning=1, grocery=1, Welcome=1, is=1, to=1, store=3, Good=1, my=2}

```

MY OUTPUT

```
{=2, a=1, Morning=1, grocery=1, Welcome=1, is=1, to=1, store=3, Good=1, my=1, My=1}

```

Answer: 
A few suggestions for you to consider:

In regular expressions, `\W` refers to anything that isn't a word character (i.e anything that isn't a letter).

If you wish to split on any punctuation or spaces then you should have a `+` after `\W` in your regexp. This will count all of the subsequent ones as part of the same delimiter. That's why you are currently getting `{=2` in your answer (there are two instances of ". " in your input which are interpreted by the split as delimiter, null, delimiter).

It looks as though you want 'my' and 'My' to be considered the same string. In that case you should use `toLowerCase` before adding them to the map.

If you are using Java 8 a nice easy way to maintain a running increment in a map is

```
Map<String,Integer> wordCount = new HashMap<>();
wordCount.put(word, wordCount.getOrDefault(word, 0) + 1);

```

Again, with Java 8, you can do all of this in one go

```
Map<String,Long> wordCount = Arrays.stream(phrase.toLowerCase().split("\\W+"))
    .collect(Collectors.groupingBy(Function.identy(), Collectors.counting());

```
Your approach is not exactly correct (what if you have other symbols there?). Do this :

> 
> 1. Replace all non-alphanumeric characters with spaces.
> 2. Split based space (`\\s+`).
> 3. For each string in the split array : a. Check if you have a key equal to the string : YES : get the value, increment the count and
>  put the value back. No : insert new key with value =1
> 
> 
>