Using ArrayList<int>

You are effectively doing a flood fill and there are many good algorithms out there that can do this efficiently. You might want to look at them.