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: 
I'm gonna build upon sprinters answer since he completely ignored what could and couldnt be changed in the question.

Using as nuch Java 8 as possible. This wouldnt really work in your case since the map is already initialized so it weird that youre creating another and replacing it

```
map = Arrays.stream(ignored)
        .filter(s -> !s.isEmpty()) // removed empty strings
        .map(String::toLowerCase) // makes all the strings lower case
        .collect(Collectors.groupingBy(Function.identy(), Collectors.counting());

```

Using more basic Java 8 features and using the originally created map.

```
Arrays.stream(ignored)
        .filter(s -> !s.isEmpty()) // removed empty strings
        .map(String::toLowerCase) // makes all the strings lower case
        .forEach(s -> map.put(s, map.getOrDefault(s, 0) + 1)

```

No Java 8

```
for (final String s : ignored) {
    if (s.isEmpty()) {
        continue; // skip empty strings
    }
    final String lowerS = s.toLowerCase();
    if (map.containsKey(lowerS)) {
        map.put(lowerS, map.get(lowerS) + 1)
    } else {
        map.put(lowerS, 1)
    }
}

```
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
> 
> 
>