title: Accessing an array in another method
body: <p>I am trying to access an array in a separate method that it is initialized in.</p>
  
  <pre><code>public void initializeArray()
  {                
      String sentences[] = new String[5];
  
      for(int i=0; i&lt;5; i++)
      { 
          sentences[i] = i+1;
      }
  }
  
  public void printArray()
  {
      for(int i=0; i&lt;5; i++)
      {
          System.out.println(sentences[i]);
      }
  }
  </code></pre>
  
  <p>I know that I could do this in one for loop, but can someone explain how I could print the array this way? I need to access the sentences array in a separate method that it is initialized in. I tried to make an instance of the array at the top of the program but it gives me an error saying "Local variable hides a field".</p>