title: initializing ArrayList<>() in methods or constructor
body: <pre><code>import java.util.ArrayList;
  public class Team {  
  
      private String name;
      private ArrayList&lt;Player&gt; team;
  
      public Team(String name)    {
          this.name = name;
          //how come i have to initialize it here in the constructor to see the full list?          
          this.team = new ArrayList&lt;Player&gt;();
      }
  
      public void addPlayer(Player player)    {
          //why can't i initialize it here in the method, this gives me a list of only recent add?
          //this.team = new ArrayList&lt;Player&gt;(); 
          this.team.add(player);
      }
  
      public void printPlayers()  {            
          for(Player players : this.team) {
              System.out.println(players);
          }
      }
      public String getName() { return this.name; }
  }
  </code></pre>
  
  <ul>
  <li>I'm trying to figure out why <code>this.team = new ArrayList&lt;Player&gt;()</code> have to be in the constructor?</li>
  <li>Why can't I have <code>this.team = new ArrayList&lt;Player&gt;()</code> initialized in the method?</li>
  <li>I know that when I run it with the code in the constructor it works as intended (it gives me the full list when things are added)</li>
  <li>BUT when it's initialized in the method it only list the last given addition to the list. Is it wrong to have it initialized in the method?</li>
  <li>Also what's the difference of having it initialized as <code>private ArrayList&lt;Player&gt; team = new ArrayList&lt;Player&gt;();</code> before the constructor?</li>
  </ul>