Loop through the string and use String.regionMatches. If there is a match, don't just jump to the next character but go forward match.length(), where match is either aBa or aaa.
Altenatively, you could use a combination of indexOf calls:
You would have to test
to see which of these two algorithms is faster, but I think it also depends on the number of occurrances.