Find shape within a rows of characters-Java : I came across to problem on thinking how to get the shape from the rows of characters, for example

AAAAAAAA

ABBBAABA

ABABABBB

ABBBAAAA

AAAABBAA

ABBABBAA

ABBABBAA

ABAABBAA

which has A and B characters, and I want to calculate how many 'B' shape are there, what I mean by shape is that the 'B' are near each other and form shape like rectangular and triangle. The example has 4 shapes(hope you can see the shape)
I am able to calculate how many 'B' are there, and then I tried to get the index number out of the rows with this code(it is not correct code, but I still have some questions because it does not give me the correct index number of the 'B')

    int indexZero = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int a = 1; a < count; a++)
		{
			for(int b = 0; b < count - 1; b++)
			{
				indexZero = array[a].indexOf('B');
				list.add(indexZero);

			}
		}
		System.out.println(list);

The result was [-1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Because the for loop it became so many numbers, but I still wonder why only 1 and 4 appear when there are also 2, 3, 5, 7 which missing from the result.

I am still new to Java, so I want to ask is there is any java function that can check the same occurrence that near to each other in order to count the shape appears? Hope you can give me some pointer on how to construct this algorithm.
(I have thought of taking each index of 'B' and check whether they are near to other 'B' but I get stuck)