Java Learning 3_ some basic 3_16.5.7

Source: Internet
Author: User

Some common methods of strings:

int Length ()

String replace (charsequence oldstring,charsequence newstring)

Returns the string with the new string instead of the original string.

String substring (int beginindex)

String substring (int beginindex,int endIndex)

Returns a new string. This string contains all the code units from the Beginindex to the tail string or endIndex-1 in the original string.

String toLowerCase ()

String toUpperCase ()

StringBuilder class:

Sometimes a string, such as a key or a word from a file, needs to be built from a shorter string. The use of string connections to achieve this goal is less efficient. Each time a connection string is built, a new string object is constructed, which is time consuming and wasteful. This problem can be avoided by using the StringBuilder class.

If you need to build a string with many small pieces of string, first build an empty string builder, and then call the Append method each time you add

StringBuilder builder=new StringBuilder ();

Builder.append (CH); Append a single character

Buildr.append (str); Append a string

Call the ToString method when you need to build a string

String completedstring=builder.tostring ();

Some methods of the StringBuilder class:

int Length ()

StringBuilder Append (String str)

StringBuilder append (char c)

void Setcharat (int i,char c)//Set the I unit of code to C

StringBuilder Insert (int offset,char c)//Inserts a unit of code at offset position and returns this

StringBuilder Insert (int offset,string str)

StringBuilder Delete (int startindex,int endIndex)//delete the code unit from StartIndex to EndIndex-1 and return this

String toString ()

Java Learning 3_ some basic 3_16.5.7

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.