String construction method and character set encoding conversion

Source: Internet
Author: User

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

String construction method and character set encoding conversion

String (): new string () generates "" empty string object, not null,null not pointing to memory;
String (java.lang.String): New String ("AAA"), each time creating a memory storage string;
String (char[]): char[] ch={' A ', ' B ', ' C '},new string (CH) converts the character array to the string "ABC";
String (byte[], java.lang.String): Parameter 1 is a byte[] byte array, parameter 2 String is a character set, such as "GBK", "UTF-8", Examples:

Casts a byte array into a set of character sets;
String (byte[]): Converts a byte array into a string by the system default character set encoding format;
GetBytes (): Converts a string to a byte array by the system's default character set, example:

GetBytes (java.lang.String): Install the passed-in character set for conversion, example:

Length (): Returns the length of the string (by the number of characters);
IsEmpty (): Judging is not an empty string "", is the return true, not to return false, not to judge Null;
Trim (): Remove left and right spaces (middle space cannot be removed);
toLowerCase (): string turns lowercase;
toUpperCase (): string to uppercase;
Split (java.lang.String): separates by specific characters, returns an array of strings, examples:

indexOf (int): Finds the first occurrence in a string by the given character, and returns the subscript number of type int;
IndexOf (java.lang.String): Find the place where the string first appears, example:

LastIndexOf (String): Find the first occurrence of a string from behind, example:

IndexOf (java.lang.String, int): Set an index to start the search to find the string, return the position of the subscript where the string appears, example:

charAt (int): Returns the character according to the given subscript, example:

substring (int, int): Intercepts a string, parameter 1 is the subscript to start intercepting, parameter 2 is the subscript to end the interception, example:

SUBSTRING (int): From the given start subscript backward interception, example:

StartsWith (java.lang.String): Determines the string prefix, returns a Boolean value, example:

EndsWith (String): determines the string suffix;
Equals (String): Determines whether the contents of two string objects are the same, returns a Boolean value, example:

Replace (Oldchar,newchar): Replacement character, example:

Replace (Java.lang.CharSequence, java.lang.CharSequence): replacement string, Parameter 1 is the old string, that is, the replaced string; parameter 2 is a new string, example:

ReplaceAll Replace all, you need to use regular expressions,

String construction method and character set encoding conversion

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.