I hava again run it interesting problem, I need to dynamically build SQL query which contatins the IN condition. So I have list of String and I need to insert them to my StringBuilder separated by the coma.
So my first idea was to employ some boolean value to determine if I should insert the coma or not.
builder.append("TABLE.METACODES in (");
boolean isFirst = true;
for(String metaCode : cto.getEntityMetaCodes()) {
if(isFirst) {
isFirst = false;
builder.append("'" + metaCode + "'");
} else {
builder.append(", '" + metaCode + "'");
}
}
builder.append(")");
Can yout think of any better solution?
Without using an external library, I would do something like: