Java review notes ---- string

Source: Internet
Author: User

A Java string is a Unicode Character Sequence. Java does not have a built-in String type. Instead, a predefined String class is provided in the standard Java class library, which is located in the java. lang package. The Compiler imports this package by default. Strings are processed as String objects.

Method for creating a String object:

1. String s = "Hello World ";

2. String s = new String ();

3. String s = new String ("Hello World ");

 

Obtain the length of a string: string name. length ();

 

String comparison: String 1. equals (string 2); // the same letter, the same case is different

String 1. Using signorecase (string 2); // case insensitive during comparison

The English character in the toLowerCase () Conversion string is lowercase.

The English characters in the toUpperCase () Conversion string are uppercase letters.

 

String connection:

1. Use the "+" operator,

2. Use the concat () method of the String class

 

Common string extraction and query methods:

Method description
Public int indexOf (int ch) searches for the first occurrence character ch
Public int indexOf (String value) Search for the first occurrence String value
Public int lastIndexOf (int ch) searches for the last occurrence character ch
Public int lastIndexOf (String Value) Search for the last String value
Public String substring (int index) extract the String part starting from the Position index
Public String substring (int beginIndex, int endIndex); extract the String section between beginIndex and endIndex
Public String trim () removes leading and trailing spaces of the String and returns a copy.

Related Article

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.