I am building a validation routine that validates contents and then gives warning (for failures) in form of StringBuilder. Say in below code I am checking lower bound for values paramX and paramY.
StringBuilder sb= new StringBuilder();
if(paramX<10){
sb.append("paramX cannot be less than 10 ");
}
if(paramY<20){
sb.append("paramY cannot be less than 20 ");
}
System.out.println(sb);
It gives output as: paramX cannot be less than 10 paramY cannot be less than 20
but i want output such that, each appended String will be printed on new line. Like below.
paramX cannot be less than 10
paramY cannot be less than 20
I used following workarounds, but ended up repeating same code again and again(Which i don't want to).
sb.append(System.getProperty("line.separator")); // Add Explicit line separator each time
sb.append("\n");
sb.append("paramX cannot be less than 10 \n");
Is there a simpler way to do it?
sb.append("xxxx\n");
- why not this? – BelisleSB
and add corresponding method e.g.appendLine()
– Belisle