Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Why should you useStringBuilder objects instead of String objects in a program

ID: 3610914 • Letter: 1

Question

1.Why should you useStringBuilder objects instead of String objects in
a program that makes lots of changes to strings?

2.A good program reads a string as input from the user for thepurpose of
tokenizing it.Why is it a good idea you trim the string beforetokenizing it?

3.Each of the numeric wrapper classes has a "parse" method. What dothese
methods do?

4.Each of the numeric wrapper classes has a static toString method.What do
thses methods do?

5.How can you determine the minimum and the maximum values that canbe
stored in a variable of a given data type? 1.Why should you useStringBuilder objects instead of String objects in
a program that makes lots of changes to strings?

2.A good program reads a string as input from the user for thepurpose of
tokenizing it.Why is it a good idea you trim the string beforetokenizing it?

3.Each of the numeric wrapper classes has a "parse" method. What dothese
methods do?

4.Each of the numeric wrapper classes has a static toString method.What do
thses methods do?

5.How can you determine the minimum and the maximum values that canbe
stored in a variable of a given data type?

Explanation / Answer

1)

We should use StringBuilder in preference overStringBuffer. In fact, the J2SE 5.0 javac compilernormally uses StringBuilder instead of StringBuffer whenever youperform string concatenation as in

System.out.println ("The result is " + result);

All the methods available on StringBuffer are also available onStringBuilder, so it really is a drop-in replacement.

2)

The process of breaking a string into tokens is known astokenizing.We will need to know the basic needs of a goodtokenizer. Since Java developers are used to the StringTokenizerclass, a good tokenizer should have all the useful methods thatclass provides, such as hasMoreTokens(), nextToken(),countTokens().

3)

The parse methods all throw a NumberFormatException ifthe string object does not represent a numeric value.

4)

Each of the numeric wrapper classes has a statictoString method that converts a number to a string.

5)

The numeric wrapper classes each have a set of staticfinal variables

MIN_VALUE and

MAX_VALUE.

These variables hold the minimum and maximum values fora particular data type.

System.out.println("The minimum value for an"

                  + "int is “

                  + Integer.MIN_VALUE);

System.out.println("The maximum value for an"

                  + "int is“

                  + Integer.MAX_VALUE);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote