JAVA method for StringBuffer, javastringbuffer

Source: Internet
Author: User

JAVA method for StringBuffer, javastringbuffer

Public final classStringBufferExtends Objectimplements Serializable, CharSequence

I. constructor:

1. public StringBuffer (): constructs a string buffer with no characters. The initial capacity is 16 characters.

 

2. public StringBuffer (int capacity): constructs a string buffer with no characters and the specified initial capacity.

 

3. public StringBuffer (String str): constructs a String buffer that is initialized to the specified String content. The initial capacity of the String buffer is 16 plus the length of the String parameter.

 

4. public StringBuffer (CharSequence seq) constructs a string buffer CharSequence containing the same characters as the specified one. The initial size of the string buffer is 16 plus the length of the CharSequence parameter. If the length of the specified CharSequence is less than or equal to zero, the capacity of the null buffer 16 is returned.

 

Ii. Common Methods:

 

1. public StringBuffer append (boolean B)
Attaches the string representation of the boolean parameter to the sequence. This method can also be usedChar, int, long, float, and double.

2. public StringBuffer delete (int start, int end ):
Delete the characters in the substring of this sequence. The substring starts with the specified start and extends to the character index end-1. If start is equal to end, no changes are made.

3. public StringBuffer deleteCharAt (int index ):
Delete the specified position of a char in the sequence, which is shortened by a char.

4. public StringBuffer replace (int start, int end, String str ):
Replace the substring of this sequence with the str character in the specified String, that is, the String starting from start and extending to the character index end-1. (If needed, this sequence will be extended to accommodate the specified string .)

5. public String substring (int start ):
Returns a new String starting from the specified index and extending to the end of the String.

6. public String substring (int start, int end ):
Returns a new String from the specified start and extended to the index number end-1.

7. public StringBuffer insert (int index, char [] ch, int offset, int len ):
Insert the string index into the string array ch, which starts from index offset and is a string of len characters. The length of the sequence increases by len.

8. public StringBuffer insert (int offset, Object obj ):
Insert the obj string to the offset position of the Character Sequence. (Equivalent to converting String. valueOf (obj) to a String before insertion .) It can also be appliedString, char [], char, int, lont, float, double.

9. public int indexOf (String str ):
Returns the index that str appears in the string for the first time.

10. public int indexOf (String str, int fromIndex ):
Returns the index that str appears in the string for the first time and starts searching from the specified index fromIndex.

11. public int lastIndexOf (String str ):
Returns the index of str that appears in the string for the last time.

12. public int lastIndexOf (String str, int fromIndex ):
Returns the index of str that appears in the string for the last time, starting from the specified index fromIndex.

13. public StringBuffer reverse ():
Reverse the character sequence.

14. public String toString ():
Converts the StringBuffer type to the String type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.