Tidying Up Java Basics--stringbuffer&stringbuilder class

Source: Internet
Author: User

StringBuffer class & StringBuilder class
String length size is not variable
StringBuffer and StringBuilder length variable
StringBuffer thread-Safe StringBuilder thread is unsafe
Fast StringBuilder Speed
Objects of the StringBuffer class & StringBuilder class can be modified multiple times and do not produce new unused objects (strings produce new, and are more memory-intensive)
StringBuffer Method
1. Specify the string append character to this character sequence
xxxx.append("520");
2. Reverse the character sequence
xxxx.reverse()No parameters Required
3. Removing strings from a character sequence
xxxx.delete(2,5)//2为字符开始位置 5为结束位
4. Inserts an integer into the sequence and can specify where to insert it
xxxx.insert(2,520);//2表示插入的位置,520是整数 将以字符串的形式插入
5. Replace substring B in the sequence with the specified string a
xxxx.replace(0,17,“520”)//0&17是起始终止位置 “520”是字符串
6. Return the current capacity
xxxx.capacity()//无需参数
7. Returns the character value of the specified position in the sequence
xxxx.charAt(5)
8. Ensure capacity at least equal to the specified minimum value
xxxx.ensureCapacity(int minimumCapacity)
9. Copy the string/character to the target character array
xxxx.getChars(start,end,char,start)后一个start是字符数组的起始位置
10. Returns the position of the first occurrence of the substring in the string
xxxx.indexOf(String str)
11. Starting at the specified position, returns the position of the first occurrence of the substring in the string
xxxx.indexOf(String str,int fromIndex);
12. Returns the position of the specified string at the far right
xxxx.lastIndexOf(String str);
13. Starting at the specified position returns the rightmost occurrence of the specified string at the position of the string
xxxx.lastIndexOf(String str,int fromIndex)
14. Returns the length of the string (different from capacity)
xxxx.length()//无需参数
15. Set CH at the position of the specified string (will replace the character at the original position)
xxxx.setCharAt(int index,char ch);
16. Set the length of the character sequence
xxxx.setLength(int newLength);
17. Returns a new sequence of characters that is a subsequence of this sequence.
CharSequence ch =xxxx.subSequence(int start,int end);
18. Returns a new String that contains the subsequence of this sequence from the specified position
String str = xxxx.substring(int start);
19. Returns the string representation of the data in this sequence.
xxxx.toString();

Tidying Up Java Basics--stringbuffer&stringbuilder class

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.