title: Best practice for initializing an ArrayList field in Java
body: <p>What's the best practice for initializing an ArrayList field in Java (to avoid testing null value) ?</p>
  
  <p>At declaration, like this : </p>
  
  <pre><code>private List&lt;String&gt; myList = new ArrayList&lt;String&gt;();
  </code></pre>
  
  <p>Or in the getter, like this : </p>
  
  <pre><code>public List&lt;String&gt; getMyList() {
      if(myList == null) {
          myList = new ArrayList&lt;String&gt;();
      }
      return myList;
  }
  </code></pre>
  
  <p>Or, in the constructor : </p>
  
  <pre><code>public Test(){
      myList = new ArrayList&lt;String&gt;();
  }
  </code></pre>
  
  <p>Maybe it's the same, but I am curious to know.</p>