src/share/classes/java/lang/StringBuffer.java

Print this page
rev 10048 : 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
Reviewed-by:


  75  * <p>
  76  * Every string buffer has a capacity. As long as the length of the
  77  * character sequence contained in the string buffer does not exceed
  78  * the capacity, it is not necessary to allocate a new internal
  79  * buffer array. If the internal buffer overflows, it is
  80  * automatically made larger.
  81  * <p>
  82  * Unless otherwise noted, passing a {@code null} argument to a constructor
  83  * or method in this class will cause a {@link NullPointerException} to be
  84  * thrown.
  85  * <p>
  86  * As of  release JDK 5, this class has been supplemented with an equivalent
  87  * class designed for use by a single thread, {@link StringBuilder}.  The
  88  * {@code StringBuilder} class should generally be used in preference to
  89  * this one, as it supports all of the same operations but it is faster, as
  90  * it performs no synchronization.
  91  *
  92  * @author      Arthur van Hoff
  93  * @see     java.lang.StringBuilder
  94  * @see     java.lang.String
  95  * @since   JDK1.0
  96  */
  97  public final class StringBuffer
  98     extends AbstractStringBuilder
  99     implements java.io.Serializable, CharSequence
 100 {
 101 
 102     /**
 103      * A cache of the last value returned by toString. Cleared
 104      * whenever the StringBuffer is modified.
 105      */
 106     private transient char[] toStringCache;
 107 
 108     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 109     static final long serialVersionUID = 3388685877147921107L;
 110 
 111     /**
 112      * Constructs a string buffer with no characters in it and an
 113      * initial capacity of 16 characters.
 114      */
 115     public StringBuffer() {


 639     }
 640 
 641     /**
 642      * @since      1.4
 643      */
 644     @Override
 645     public int lastIndexOf(String str) {
 646         // Note, synchronization achieved via invocations of other StringBuffer methods
 647         return lastIndexOf(str, count);
 648     }
 649 
 650     /**
 651      * @since      1.4
 652      */
 653     @Override
 654     public synchronized int lastIndexOf(String str, int fromIndex) {
 655         return super.lastIndexOf(str, fromIndex);
 656     }
 657 
 658     /**
 659      * @since   JDK1.0.2
 660      */
 661     @Override
 662     public synchronized StringBuffer reverse() {
 663         toStringCache = null;
 664         super.reverse();
 665         return this;
 666     }
 667 
 668     @Override
 669     public synchronized String toString() {
 670         if (toStringCache == null) {
 671             toStringCache = Arrays.copyOfRange(value, 0, count);
 672         }
 673         return new String(toStringCache, true);
 674     }
 675 
 676     /**
 677      * Serializable fields for StringBuffer.
 678      *
 679      * @serialField value  char[]




  75  * <p>
  76  * Every string buffer has a capacity. As long as the length of the
  77  * character sequence contained in the string buffer does not exceed
  78  * the capacity, it is not necessary to allocate a new internal
  79  * buffer array. If the internal buffer overflows, it is
  80  * automatically made larger.
  81  * <p>
  82  * Unless otherwise noted, passing a {@code null} argument to a constructor
  83  * or method in this class will cause a {@link NullPointerException} to be
  84  * thrown.
  85  * <p>
  86  * As of  release JDK 5, this class has been supplemented with an equivalent
  87  * class designed for use by a single thread, {@link StringBuilder}.  The
  88  * {@code StringBuilder} class should generally be used in preference to
  89  * this one, as it supports all of the same operations but it is faster, as
  90  * it performs no synchronization.
  91  *
  92  * @author      Arthur van Hoff
  93  * @see     java.lang.StringBuilder
  94  * @see     java.lang.String
  95  * @since   1.0
  96  */
  97  public final class StringBuffer
  98     extends AbstractStringBuilder
  99     implements java.io.Serializable, CharSequence
 100 {
 101 
 102     /**
 103      * A cache of the last value returned by toString. Cleared
 104      * whenever the StringBuffer is modified.
 105      */
 106     private transient char[] toStringCache;
 107 
 108     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 109     static final long serialVersionUID = 3388685877147921107L;
 110 
 111     /**
 112      * Constructs a string buffer with no characters in it and an
 113      * initial capacity of 16 characters.
 114      */
 115     public StringBuffer() {


 639     }
 640 
 641     /**
 642      * @since      1.4
 643      */
 644     @Override
 645     public int lastIndexOf(String str) {
 646         // Note, synchronization achieved via invocations of other StringBuffer methods
 647         return lastIndexOf(str, count);
 648     }
 649 
 650     /**
 651      * @since      1.4
 652      */
 653     @Override
 654     public synchronized int lastIndexOf(String str, int fromIndex) {
 655         return super.lastIndexOf(str, fromIndex);
 656     }
 657 
 658     /**
 659      * @since   1.0.2
 660      */
 661     @Override
 662     public synchronized StringBuffer reverse() {
 663         toStringCache = null;
 664         super.reverse();
 665         return this;
 666     }
 667 
 668     @Override
 669     public synchronized String toString() {
 670         if (toStringCache == null) {
 671             toStringCache = Arrays.copyOfRange(value, 0, count);
 672         }
 673         return new String(toStringCache, true);
 674     }
 675 
 676     /**
 677      * Serializable fields for StringBuffer.
 678      *
 679      * @serialField value  char[]