< prev index next >

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

Print this page
rev 54260 : 8221430: StringBuffer(CharSequence) constructor truncates when -XX:-CompactStrings specified


 145      * {@code 16} plus the length of the string argument.
 146      *
 147      * @param   str   the initial contents of the buffer.
 148      */
 149     @HotSpotIntrinsicCandidate
 150     public StringBuffer(String str) {
 151         super(str.coder(), str.length(), 16);
 152         append(str);
 153     }
 154 
 155     /**
 156      * Constructs a string buffer that contains the same characters
 157      * as the specified {@code CharSequence}. The initial capacity of
 158      * the string buffer is {@code 16} plus the length of the
 159      * {@code CharSequence} argument.
 160      *
 161      * @param      seq   the sequence to copy.
 162      * @since 1.5
 163      */
 164     public StringBuffer(CharSequence seq) {
 165         super(String.LATIN1, seq.length(), 16);
 166         append(seq);
 167     }
 168 
 169     /**
 170      * Compares two {@code StringBuffer} instances lexicographically. This method
 171      * follows the same rules for lexicographical comparison as defined in the
 172      * {@linkplain java.lang.CharSequence#compare(java.lang.CharSequence,
 173      * java.lang.CharSequence)  CharSequence.compare(this, another)} method.
 174      *
 175      * <p>
 176      * For finer-grained, locale-sensitive String comparison, refer to
 177      * {@link java.text.Collator}.
 178      *
 179      * @implNote
 180      * This method synchronizes on {@code this}, the current object, but not
 181      * {@code StringBuffer another} with which {@code this StringBuffer} is compared.
 182      *
 183      * @param another the {@code StringBuffer} to be compared with
 184      *
 185      * @return  the value {@code 0} if this {@code StringBuffer} contains the same




 145      * {@code 16} plus the length of the string argument.
 146      *
 147      * @param   str   the initial contents of the buffer.
 148      */
 149     @HotSpotIntrinsicCandidate
 150     public StringBuffer(String str) {
 151         super(str.coder(), str.length(), 16);
 152         append(str);
 153     }
 154 
 155     /**
 156      * Constructs a string buffer that contains the same characters
 157      * as the specified {@code CharSequence}. The initial capacity of
 158      * the string buffer is {@code 16} plus the length of the
 159      * {@code CharSequence} argument.
 160      *
 161      * @param      seq   the sequence to copy.
 162      * @since 1.5
 163      */
 164     public StringBuffer(CharSequence seq) {
 165         super(getCharSequenceCoder(seq), seq.length(), 16);
 166         append(seq);
 167     }
 168 
 169     /**
 170      * Compares two {@code StringBuffer} instances lexicographically. This method
 171      * follows the same rules for lexicographical comparison as defined in the
 172      * {@linkplain java.lang.CharSequence#compare(java.lang.CharSequence,
 173      * java.lang.CharSequence)  CharSequence.compare(this, another)} method.
 174      *
 175      * <p>
 176      * For finer-grained, locale-sensitive String comparison, refer to
 177      * {@link java.text.Collator}.
 178      *
 179      * @implNote
 180      * This method synchronizes on {@code this}, the current object, but not
 181      * {@code StringBuffer another} with which {@code this StringBuffer} is compared.
 182      *
 183      * @param another the {@code StringBuffer} to be compared with
 184      *
 185      * @return  the value {@code 0} if this {@code StringBuffer} contains the same


< prev index next >