title: get first and last element in ArrayList in Java
body: <p>I have small code where i have to add condition to get proper output.</p>
  
  <p>if the element inside the mimeList is Last then go to <strong>else</strong> part.
  or to the <strong>if</strong>.</p>
  
  <p>there is always 1 element in this ArrayList.</p>
  
  <p>(if it has only one element then it means it is  last element.)</p>
  
  <pre><code>for (int i = 0; i &lt; mimeList.size(); i++) {
      StringBuffer sb = new StringBuffer();
  
      if () {
          queryString = sb.append(queryString).append(key)
          .append("=").append(mimeList.get(i)).append(" or ").toString();
      }else{
          queryString = sb.append(queryString).append(key)
          .append("=").append(mimeList.get(i)).toString();
      }
  }
  </code></pre>