What would your preferred loop type be for a case like this:StringBuilder sb = new StringBuilder();for(Integer id : idList) {    sb.append(?,);}In short: In dependency to the size of a List i want to add stuff to a String. The above example produces a unused variable warning.I'm thinking of these alternatives:for(int i=0; i<idList.size(); i++) {    // ...}I don't really like all the extra typing there...Iterator it = idList.iterator();while(it.hasNext()) {    // ...    it.next();}The loop head itself looks nice, but i end up typing a lot of extra code (getting the iterator, moving to the next element...)What I'd like to do would be something like that:for(idList) {    // ...}Is there a better style/What is the best kind of style for that kind of loop?
Simplify a loop
java
I would use a normal string repeating method:String s = repeat(?,, idList.size());Unfortunately Java doesn't have such a method in the standard API. So you could write one yourself:String repeat(String s, count i) {  StringBuilder sb = new StringBuilder();  while (i-- > 0) {     ab.append(s);  }  return sb.toString();}or use one provided by several standard add-on APIs such as Apache Commons' StringUtils.repeat().