Java--string Class (Common Class)

Source: Internet
Author: User

One, String class--describes the common methods of the string is briefly described:

1.charAt () Gets the character of the corresponding position

2.length () Gets the length of the string

3.concat () append content at the end of the string-----equivalent to a connector (+)

4.contains () to see if the string contains the specified content

5.endWith () to see if the string ends with XXX (can be used to view the file format)

6.startWith () to see if the string starts with XXX

7.equals () compare two strings for the same content

8.indexOf () find where a given content first appears

9.lastIndexOf () Find the last occurrence of a given content

10.replace () Replace the contents of the string

11.split () Cut string

12.trim () ignores headers and trailing spaces (middle cannot be ignored)

13.subString () Truncate substring

14.getBytes () string type-->byte[] Type

15.toCharArray () string type-->char[] Type

16.toLowerCase () string all lowercase

17.toUpperCase () string all uppercase

Second, StringBuffer and StringBuilder commonly used methods of simple introduction:

1.append () append content after StringBuffer and StringBuilder strings

2.insert () Add content at the specified location

3.delete () Delete content

4.reverse () Invert string

5.setCharAt () Change the content at the specified location

Iii. differences between String, StringBuffer, and StringBuilder

1.String: Immutable sequence of characters

2.StringBuffer: Variable sequence of characters, thread synchronization (safe), low efficiency

3.Stringbuilder: variable character sequence, is thread unsynchronized (insecure), high efficiency, is a simple replacement for StringBuffer (recommended)

"StringBuffer and StringBuilder is the memory optimization of string" "

Note: The method is more, do not introduce each one, give you a link "jdk1.6 Chinese version", download down can own view.

Java--string Class (Common 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.