public interface Appender
public class MyClass implements Appender {
String a, b, c, d, e, f;
//Less efficient:
public void toString() {
StringBuilder sb=new StringBuilder();
sb.append(a);
sb.append(b);
...
sb.append(f);
return sb.toString();//Creates a large String, wasting memory.
}
//More efficient:
public void appendTo(Appendable app) {
app.append(a);
app.append(b);
...
app.append(f);//No additional Strings created.
}
}
| Modifier and Type | Method and Description |
|---|---|
void |
appendTo(java.lang.Appendable appendable)
When invoked, the Appender should print itself to the Appendable.
|