• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read stringbuffer content line by line  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The below is the code... and at last s is holding the content line by line.

public class test {
public static void main(String[] args) {

StringBuffer s = new StringBuffer();

for(int i=0;i<2;i++) {
s = s.append("abc" + "\n");
}

System.out.print(s);
}
}

s value:
abc
abc

My question is how can i read s value line by line? Please help me in this regard ASAP.
 
lee chan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the below code... you will get the line by line data

String a[] = s.toString().split("\n");
System.out.print(a[0]);
System.out.print(a[1]);
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lee chan wrote:Please help me in this regard ASAP.

Please EaseUp. Don't use words like "urgent" or "ASAP".
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!