Is there a way to re-use a Formatter in a loop or do I simply instantiate and let the garbage collector deal with it? (This is a Java question). Note if I take instantiation out of the loop, the formatted content of previous iterations through the loop will get appended to. Formatter.flush() only seems to flush, true to its name and does not give the benefit of allowing a clean slate re-use.
Example:
for (...)
{
Formatter f = new Formatter();
f.format("%d %d\n", 1, 2);
myMethod(f.toString());
}
You could use it like this:
This will reuse the Formatter and StringBuilder, which may or may not be a performance gain for your use case.