title: if(listStr.size == 0){ versus if(listStr.isEmpty()){
body: <pre><code>List&lt;String&gt; listStr = new ArrayList&lt;String&gt;();
  
  if(listStr.size == 0){
  
  }
  </code></pre>
  
  <p>versus</p>
  
  <pre><code>if(listStr.isEmpty()){
  
  }
  </code></pre>
  
  <p>In my view one of the benefits of using <code>listStr.isEmpty()</code> is that it doesn't check the size of the list and then compares it to zero, it just checks if the list is empty. Are there any other advantages as I often see <code>if(listStr.size == 0)</code> instead of <code>if(listStr.isEmpty())</code> in codebases? Is there is a reason it's checked this way that I am not aware of?</p>