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.

  1. In StringAndStringBuilder/src/com.example.stringstringbuilder.labs.StringLab, follow the instructions to print the requested information.

  2. In StringAndStringBuilder/src/com.example.stringstringbuilder.labs.StringBuilderLab, use only StringBuilder methods on the existing StringBuilder object to produce the requested result.

(Solution: StringBuilderLab.java)

  1. Modify StringAndStringBuilder/src/com.example.stringstringbuilder.drills.UserComment by adding a toString method that produces a String of the form:

On 2018-01-04 at 14:59:23, bdobbs posted this comment: [I love coding in Java!]

(Solution: UserComment.java)

  1. If your solution to the previous lab used string concatenation, modify it to instead use a StringBuilder.

(Solution: UserComment2.java)

  1. 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 that toString out and using Source | Generate toString()... again, choosing different Code style and other options.

(Solution: UserComment3.java)


Prev -- Up