i am working with a piece of code that have a StringBuilder where i will do an append of some data and then send an email with all the data. Here is the code:
StringBuilder stringBuild= new StringBuilder();
for (int i = 0; i < variable.size(); i ) { //Unknown size, could be quite big
stringBuild.append(thingsToDO((Map<String, Object>) variable.get(i)));
}
sendEmail(stringBuild);
/**
* @param stringBuild
*/
private void enviarEmail(StringBuilder stringBuild)
{
if(StringUtils.isNotBlank(stringBuild)) {
//Email OK
} else {
//Email with all errors
}
}
Is okay to use the StringUtils library for StringBuilders or there are better methods to work with StringBuilders?
I don´t have that much experience with StringBuilders so maybe i am missing something, any help is appreciated
CodePudding user response:
Try to have the Java API documentation and StringUtils API documentation at hand so you can decide whether you really need one more dependency (Apache Commons Lang) or if you want to go with the native classes only.
There are two aspects you want to keep in mind: Maintainability and performance. Maintainability means your code is easy to understand and modify. Performance wise, you'd have to profile the result to see which solution is faster.