String: Class of strings

Source: Internet
Author: User

the * override of String Equals method: The string is compared to the content, not the address value. * 1:public Boolean Equalsignorecase (String anotherstring) compares the contents of two strings, ignoring case * 2:public Boolean contains (charsequence s) determines whether the string that invokes the method contains the passed-in string * Directly as a public Boolean contains (string s). * Charsequence: Character sequence * string is a subclass of charsequence, so it can be written in the following form. The string can be passed in wherever the Charsequence type is received.  * Charsequence cs = new String ("abc"); Multi-State!  * 3: * Public boolean StartsWith (string prefix) starts with a string * public boolean endsWith (string suffix); Ends with a String * public boolean StartsWith (String prefix,int offset) starting at the specified position, beginning with a String * * 4:public Boolean isemp Ty () determines whether the string is empty (judging by the number of characters in the string, or 0, returns True)
* 1:public int Length () of the string class gets the << method of lengths!! >> Get length << properties when array!! >> * 2:public char charAt (int index) returns the character based on index * 3: * public int indexOf (int ch) returns index based on content (character) returns the first occurrence of the position * public int indexOf (String str) returns an index based on the contents (strings) returns the first occurrence of the position * public int lastIndexOf (int ch) returns an index based on content (character) returns the last occurrence of the position * public int lastIndexOf (String str) returns an index based on the contents (strings) returns the last occurrence of the position * 4: * public string substring (int beginindex) returns a new string.! Old string no changes!! Intercepts from the specified index to the last * including the starting index! * public string substring (int beginindex,int endIndex) returns a new string.!! Old string no changes!! * Start from the specified index to the end of the index *!! Contains the head does not contain the tail!!

* 1:public char[] ToCharArray () converts a string into a corresponding character array * 2:public byte[] getBytes () Use the default way to convert a string to a corresponding byte array * 3: Rewrite Tostrin The G method no longer returns the string that the address value is spelled in instead of returning the string itself * 4:public static string copyvalueof (char[] data) give me a character array, also you a string * 5:public static Strin G ValueOf (Xxx xx) give me an arbitrary object, turn it into a string * 6: * public string toLowerCase () large to small * public string touppercase () Small to large * 7:PUBL The IC string concat (String str) connects the specified string to the end of this string.

* 1 of the String class:replace (char OldChar, char Newchar) give me the old character, give me the new character, I replace the old character in the string with the new character. Replace character* Public string replace (charsequence target, charsequence replacement) Replacement String * Understood as public string replace (string old string, Strin   G new String) * * 2:public string trim () returns a copy of the string, ignoring leading and trailing blanks. To remove from the front and back blanks * * 3:public string[] Split (string regex) splits this string based on the match of the given regular expression. That is, the given character cuts the string into a corresponding number of small strings * public int


* StringBuffer: variable character sequence.  A string buffer. A container that is used to stitch strings. * * StringBuffer Construction Method: * Public StringBuffer (String str) creates a string buffer that is given a string directly within the buffer * Public stringbuffer () creates an empty string buffer * 1:public stringbuffer (int capacity) Specifies the capacity to create a string buffer * * StringBuffer Common method: * 2:public stringbuffer append (xxx xxx) Str Ingbuffer can append any type by Append Method! * Note: When added, if the capacity of the container is exceeded, the capacity is automatically incremented * 3:public int capacity () returns the container capacity * 4:public int length () return length (number of characters already stored)
* StringBuffer Other methods: * 1:public stringbuffer append (xxx xxx) append content * 2:public stringbuffer insert (int index,xxx Xxx) Insert Content * Note chained programming: When the method returns an object, you can use the object directly to continue calling the method. Repeat the action for the chained call.
* 1:public stringbuffer Delete (int start, int end) deletes the string within the specified range contains the header does not contain the tail * 2:public stringbuffer deletecharat (int index) Removes the character at the specified index position * 3:public stringbuffer replace (int start,int end, string str) replaces all content within the specified range with a new string contains the header does not contain the tail * 5:public Stringbu  Ffer reverse () flip content * Generally, in Java, the first and the end of the index, is the inclusion of the head does not contain the tail * * 4:string (byte[] bys,int startindex,int count);  The construction parameter of string does not have two indexes! Count is the number of take!

String: Class of strings

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.