Java notes--common classes

Source: Internet
Author: User

1. String class:

--Using Unicode character encoding, one character occupies two bytes;

The--string class is a final class that represents an immutable sequence of characters;

--The string is immutable, and once a string object is configured, its contents are immutable;

--Common method: 1) int length ();//return string length

2) char charAt (int index);//Returns the character of the string at index

3) int compareTo (String str);//compare with str size

4) int indexOf (string s);//Returns the position where s first appears in the string, or 1 if it does not appear.

5) int IndexOf (string s, int startPoint);//Returns the position of the first occurrence of the string after StartPoint, or 1 if it does not appear.

6) int lastIndexOf (string s);//Returns the position of the last occurrence of the string, or 1 if it does not appear.

7) int LastIndexOf (string s, int startPoint);//Returns the position of the last occurrence of the string after StartPoint, or 1 if it does not appear.

8) Boolean startwith (string prefix);//Determine if the string starts with prefix

9) Boolean endwith (string, suffix);//Determine if the string ends with suffix

A Boolean equals (Object obj);//Compare two strings for equality

One) boolean regionmatches (int firststart, String other, int otherstart, int length);// Determines whether the substring of the current string starting with Firststart is equal to the substring of the other string starting at Otherstart and length

String subString (int startPoint);//returns the substring after the string startPoint

String subString (int start, int end);//The substring that returns the string from start to end (left closed right)

() string trim ();//Returns the string after the string is removed before and after a space

String[] Split (string regex);//Use a regex delimiter to slice the string and return an array of strings

2. StringBuffer class: Variable sequence of characters

--Common methods: 1) added: Append (String | int | boolean | ...);

2) Insert: Insert (int index, string str);//Inserts the string str at the specified position index

3) Inversion: reverse ();

4) Delete: delete (int start, int end);//Remove string of specified interval

5) charAt (int index);

6) Setcharat (int index, char ch);//Modify the character at index to CH

7) Wait for a similar method as String.

3, StringBuilder class: JDK5.0 newly added, thread unsafe, efficiency is higher than stringbuffer, usage and stringbuffer similar.

4. Time-date-related classes:

Currenttimemillis () under the--system category;

--date class: Java.util.Date, Java.sql.Date

--simpledateformat class: Java.text.SimpleDateFormat

--calendar class

5. Math class: Java.lang.Math, provides a series of static methods for scientific calculations (such as ABS (), sqrt (), etc.)

Java notes--common classes

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.