Whichever way you do it, you are liable to have a program running in quadratic time.
Maybe you can create a regex for all the array, for that particular array maybe
.*(AAA)|(BBB).* or
(AAA)|(BBB)
Use matcher.find() to find all matches, and that can easily be used for counting, as Stephan said. Maybe a solution with a single regex will run in linear time, but that might not be very fast.
By the way: you posted in the
Java8 forum, but nothing posted so far is different from what it would have been in Java5.
edit: additonal: There is a
good regular expressions tutorial in the Java™ Tutorials.