String manipulation in Java?

You don't strictly need to use a StringBuffer or a StringBuilder When Java concatenates two String s, it internally uses something that is very similar to a StringBuffer Using StringBuffer directly is slightly better, though I think you won't notice it.

You don't strictly need to use a StringBuffer or a StringBuilder. When Java concatenates two Strings, it internally uses something that is very similar to a StringBuffer. Using StringBuffer directly is slightly better, though I think you won't notice it.As of the newline, use the \n character.

You can pipe many \n characters you like, that will insert some empty lines in the string. For example: s+="Course No"+i+" Section No:"+current.getSectionNo()+" CourseName:"+current. GetRepresentedCourse().getCourseName()+" Day and Time"+current.getTimeOfDay()+"\n\n"; will leave an empty line between every course.

There are some special characters you can add using some codes that start with \. See: http://www.java-tips.org/java-se-tips/java.lang/character-escape-codes-in-java.html.

– Unknown user May 3 '11 at 20:16 Put literally \n at the end of every line, and put \n\n if you want to leave an empty line, too – gd1 May 3 '11 at 20:19 this is not works good: s=s+"Course No"+i+" Section No:"+current.getSectionNo()+" Course Name:"+current. GetRepresentedCourse().getCourseName()+" Day and Time"+current.getTimeOfDay()\n; What did you mean? – Unknown user May 3 '11 at 20:23 \n has to be INSIDE the string, like any other character.

S += "some line\n" – gd1 May 3 '11 at 20:23 Or use System. GetProperty("line. Separator") - it's platform independent.

– duffymo May 3 '11 at 20:23.

Yes, please use StringBuilder: public String toString() { StringBuilder builder = new StringBuilder(); if (!this.teaches.isEmpty()) { for(Section current: this. Teaches) { builder. Append("" .

Append("Course No ") . Append(i) . Append(" Section No: ") .

Append(current.getSectionNo()) . Append(" Course Name: ") . Append(current.

GetRepresentedCourse().getCourseName()) . Append(" Day and Time ") . Append(current.getTimeOfDay()) .

Append(""); } } return builder.toString(); } Or, better yet, have a Course class instead of a bunch of raw Strings and just print out the List, calling its toString() method for each entry in the List.

Or StringBuilder if access to it is via a single thread. And add a new line via the \n character e.g. " – planetjones May 3 '11 at 20:13.

As an alternative to StringBuffer you can use StringBuilder, recommended when you don't need synchronized access. As for the newline, I'd recommend asking the System what is the appropriate end of line character(s), like this: System. GetProperty("line.

Separator").

Yes, you can construct your response with a StringBuffer or a StringBuilder (StringBuffer is thread safe but generally will be slightly less performant, so if you don't care about multi-threading use a StringBuilder) for example: StringBuilder builder = new StringBuilder(); for(Section current: this. Teaches){ builder. Append("Course No").

Append(i). Append(" Section No:"). Append(current.getSectionNo()).

Append(" Course Name:"). Append(current. GetRepresentedCourse().getCourseName()).

Append(" Day and Time"). Append(current.getTimeOfDay()); } You can include newlines using "\n" although you need to be careful using newlines as they can be system dependent, so prob better using System. GetProperty("line.

Separator").

1 Uhm, I find interesting the line. Separator part, good point. – gd1 May 3 '11 at 20:18.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions