samples/conditionaluseofapi/src/conditionaluseofapi/StringBuilderAdd15.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 03 Apr 2020 16:32:36 +0200
changeset 416 9ed8788a1a4e
permissions -rw-r--r--
Using HTTPS to download the libraries
     1 package conditionaluseofapi;
     2 
     3 /** Implementation for string concatention using Java 5 only.
     4  * 
     5  * StringBuilder is supposed to be faster than StringBuffer as it
     6  * is not synchronized and as such it is does not waste time with
     7  * synchronization when its methods are called. 
     8  *
     9  * @author Jaroslav Tulach <jtulach@netbeans.org>
    10  */
    11 final class StringBuilderAdd15 implements AddString {
    12     
    13     private StringBuilder sb = new StringBuilder();
    14 
    15     public void addString(String msg) {
    16         sb.append(msg);
    17     }
    18 
    19     public String getMessage() {
    20         return sb.toString();
    21     }
    22 
    23     public String toString() {
    24         return "New Shiny and Fast Java 5 Implementation";
    25     }
    26 }