Construct A String Using StringBuilder from a List using elements index I am a java beginner and want to build a string from elements in a list using its elements index, the code runs fine yet i want to learn if there are other ways to improve upon it.Below is my sample code and I'm welcomed to suggestions. 

String buildObject(List&lt;Integer&gt; obj){
    StringBuilder name = new StringBuilder();
   for(int i = 0; i &lt; obj.size(); i ++){
       int m = obj.size() - 1;//will be nine
       if(i == 0 &amp;&amp; i &lt; 2){
           name.append(obj.get(0))
                   .append(" &amp; ")
                   .append(obj.get(1));
       }else if (i &gt;= 2 &amp;&amp; i != m) {
           name.append(", ");//between second and before last value
            name.append(obj.get(i));
       }else if(i == m){//last value
           name.append(" and ")
                   .append(obj.get(m));
       }

   }
  return name.toString();
   }
As far as your code is concerned, it would be more efficient to apply the strings from the first 2 and the last elements outside the loop.  This will eliminate 3 elements from the loop:

String buildObject(List&lt;Integer&gt; obj){
   StringBuilder name = new StringBuilder();
   name.append(obj.get(0))
       .append(" &amp; ")
       .append(obj.get(1));
   int limit = obj.size() - 1;
   for(int i = 2; i &lt; limit; i++){
       name.append(", ");
           .append(obj.get(i));
   }
   name.append(" and ")
       .append(obj.get(limit));
   return name.toString();
}