new « StringBuffer « Java Data Type Q&A

1. What is more efficient StringBuffer new() or delete(0, sb.length())?

It is often argued that avoiding creating objects (especially in loops) is considered good practice. Then, what is most efficient regarding StringBuffer?

StringBuffer sb = new StringBuffer();
ObjectInputStream ois = ...;

for (int i=0;i<1000;i++) ...

3. get new line in StringBuffer within for loop

Hi every body, I am trying to displaying the result on every new line. This works with System.out.println. But i am debugging with System.out.print. Because I want to check with which statement, I can get new line in StringBuffer. One thing more \n works without for loop. But I do now know why it is not working within for loop. I ...