Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

get new line in StringBuffer within for loop

807601Mar 20 2008 — edited Mar 20 2008
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 will be thankfull if some body reply me because I am doing effort for last one day.

StringBuffer sb=new StringBuffer();
String txt=null;
String newLine = System.getProperty("line.separator");

for(int i=0;i<resultList.size();i++){
txt=(String) resultList.get(i);
System.out.print("Before new line:"+txt);
sb.append(txt).append(newLine);

//sb.append("\n"); sb.append("\\n");
//sb.append("\r\n");
//System.out.print("\nAfter new line:"+sb.toString());
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2008
Added on Mar 20 2008
4 comments
1,166 views