how to make a variable local
<p>I made this recursive method that calculates the longest path in a binary tree. the path its store in an arralist and then returned. however, i had to declare the array list variable global. is it possible to make this method but his the array list variable being local.</p>

<pre><code>public static &lt;T&gt; ArrayList&lt;T&gt; longestPath(BinaryNode&lt;T&gt; root){
    //ArrayList path = new ArrayList();

   if(root == null) return null;

   if(height(root.left) &gt; height(root.right)){
       path.add(root.element);

       longestPath(root.left);


   }else{
       path.add(root.element);

       longestPath(root.right);

   }

   return path;

}
</code></pre>

<p>The reason i had to make it global is because its a recursive program and every time it call itself it will create a new array list object variable with difference address if you know what i mean.</p>
