Java Fundamentals (Chapter 15)

Source: Internet
Author: User

One, String class

1. String is a class that is located in the Java.lang package

2.2 ways to create a string object:

String Variable name = "Value";

String Object name =new string ("value");

3. Common methods of string

3.1 String length--length ()

3.2 Determine if the values are equal equals ()

3.3 Determine if the string object address is the same = =

3.4 Ignore case judgment equalsignorecase ()

3.5 Case Conversion

toLowerCase ()--lowercase

toUpperCase ()--uppercase

3.6 Ways to concatenate strings

Method 1: Use the + sign

Method 2: String variable. concat (The string to concatenate);

3.7 Common methods for string extraction

The same method, with multiple representations-method overloading

3.7.1 indexOf (character or string), where the first occurrence of a character or string is found;

Returns a number, 1 means no, returns a number that is >=0, indicating the presence

3.7.2 lastIndexOf (character or string) to find the last occurrence of a character or string;

Returns a number, 1 means no, returns a number that is >=0, indicating the presence

3.7.3 substring () method

L substring (extract position): Indicates the end of extraction from the beginning of the fetch position to the end of the string

L substring (start position, end position): a substring that extracts from the start position to the end position-1 [the end position is greater than the length of the entire string, an exception occurs]

3.8 Trim ()--remove whitespace from the left and right sides of the string

3.9 String Split--split () returns an array of strings

Second, StringBuffer class

1. What is the difference between StringBuffer and string?

String space or length is fixed, stringbuffer space variable

String efficiency less than StringBuffer class

2. What are the steps of using the StringBuffer class?

Step 1: Create the object first

StringBuffer Object name =new stringbuffer ();

StringBuffer Object name =new stringbuffer (default value);

Step 2: Append or Insert values to the object

StringBuffer object name. Append (appended value);//can append any value (Char,int, etc.)

StringBuffer the object name. Insert (the position to insert, the value inserted);

Java Fundamentals (Chapter 15)

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.