Labs
The purpose of this set of labs is to get familiar with String and StringBuilder - their methods and the difference between the two classes.
-
In
StringAndStringBuilder/src/com.example.stringstringbuilder.labs.StringLab, follow the instructions to print the requested information. -
In
StringAndStringBuilder/src/com.example.stringstringbuilder.labs.StringBuilderLab, use onlyStringBuildermethods on the existingStringBuilderobject to produce the requested result.
(Solution: StringBuilderLab.java)
- Modify
StringAndStringBuilder/src/com.example.stringstringbuilder.drills.UserCommentby adding atoStringmethod that produces aStringof the form:
On 2018-01-04 at 14:59:23, bdobbs posted this comment: [I love coding in Java!]
(Solution: UserComment.java)
- If your solution to the previous lab used string concatenation, modify it to instead use a
StringBuilder.
(Solution: UserComment2.java)
- Comment out your
toString. Under the Eclipse Source menu, select Generate toString()... and hit OK, accepting all the defaults. Observe the result. Experiment by commenting thattoStringout and using Source | Generate toString()... again, choosing different Code style and other options.
(Solution: UserComment3.java)