Java: how to turn local references created in for loop into global references?
<p>How to create local references created in for loop into global references?   The following code wont compile:  </p>

<p>Also, in real project, the number of t's and type of t's are data driven (I'm looping through a map of maps to make decision), so I cannot specify t before starting for loop.....</p>

<pre><code>public class TestLocal{
  public static void main(String [] args){

  for (int i=1; i&lt;1; i++){
    TestLocal t=new TestLocal();
   }
   System.out.println("This is the new object:  " + t );
 }
}
</code></pre>

<p>How could I make t accessible from outside for loop?</p>

<p><strong>more code</strong></p>

<p>Note: </p>

<p>1)test has many values, and what instance to create depends on its value.</p>

<p>2) since I'm looping through a map of maps which are data driven, the number of instances to be created depend on the number of inner maps......</p>

<pre><code>                        for (int i=0;i&lt;sortedMap.size();i++){
                           ArrayList&lt;Object&gt; a = new ArrayList&lt;Object&gt;(sortedMap.keySet());
                           Object o=a.get(i);
                           HashMap m=(HashMap)sortedMap.get(o);
                           int test = ((Number)m.get("textType")).intValue();
                          if (test==3){
                           System.out.println("all together: " + sortedMap.size() + "each element is:  " + o + " value: " + m.get("textType"));
                           String mytest = (String)m.get("text");
                           ChapterAutoNumber chapter1 = new ChapterAutoNumber(mytest);
                        }
</code></pre>
