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?