Recursive Array Traversal Problems
<p>I am having some stackoverflow issues and hopefully someone can give me some insight into a non/less-recursive solution.</p>

<pre><code>Ident[][] map = ...

private int explore(Ident item, int xcoord, int ycoord) {
    if ((map[xcoord][ycoord] == null) || !map[xcoord][ycoord].equals(item))
             return 0;

    map[xcoord][ycoord] = null;
    int sumX, sumY, counter = 1;
    item.translate(xcoord, ycoord);

    for (int y = -1; y &lt;= 1; y++)
        for (int x = -1; x &lt;= 1; x++) {
             sumX = x + xcoord;
             sumY = y + ycoord;
            if (((y != 0) || (x != 0)) &amp;&amp; (sumX &gt;= 0) &amp;&amp; (sumX &lt; map.length) &amp;&amp; 
                     (sumY &gt;= 0) &amp;&amp; (sumY &lt; map.[0].length))
                     counter += explore(item, sumX, sumY);
             }
        }
    }
    return counter;
}
</code></pre>

<p>This method is given a 2-dimensional array of Ident Objects, a target Ident and a starting position within the array. It recursively traverses the array 
counting how large of a continuous area the Ident occupies. It also centers the inputted Ident item in the middle of the area. </p>

<p>By looping through the map array and calling the explore method on any non null elements I can construct an array of Ident items centered in their areas, and with sizes relative to their areas. </p>

<p>One can see that with anything but small maps, the stack will overflow. </p>

<p>Anyone have an alternate method of accomplishing the same task? Or some insight to help me find one?</p>
