Java counting occurrences not working with spaces

   public static int countOccurrences(String haystack, char needle)
{
    int count = 0;
    for (int i=0; i < haystack.length(); i++)
    {
        if (haystack.charAt(i) == needle)
        {
             count++;
        }
    }
    return count;
}

i have the next method and i'm trying to count letter's A's with the next input "I am an instance with four a's." it shoulda give 4 letters A's but it give me 0 and when i try to put the same string but without whitespaces and give me the right output i tried to removes whitespaces Scanner in = new Scanner(System.in);

      String st=in.next();

      st = st.replaceAll("\\s","");



      System.out.println(countOccurrences(st,'a')); 

but still the same result what could be wrong