Class StringExperiment

java.lang.Object
com.zybooks.dsaj.analysis.StringExperiment

public class StringExperiment extends Object
Provides an empirical test of the efficiency of repeated string concatentation versus use of the StringBuilder class.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    main(String[] args)
    Tests the two versions of the 'repeat' algorithm, doubling the size of n each trial, beginning with the given start value.
    static String
    repeat1(char c, int n)
    Uses repeated concatenation to compose a String with n copies of character c.
    static String
    repeat2(char c, int n)
    Uses StringBuilder to compose a String with n copies of character c.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StringExperiment

      public StringExperiment()
  • Method Details

    • repeat1

      public static String repeat1(char c, int n)
      Uses repeated concatenation to compose a String with n copies of character c.
    • repeat2

      public static String repeat2(char c, int n)
      Uses StringBuilder to compose a String with n copies of character c.
    • main

      public static void main(String[] args)
      Tests the two versions of the 'repeat' algorithm, doubling the size of n each trial, beginning with the given start value. The first command line argument can be used to change the number of trials, and the second to adjust the start value.