Java11-1 the most common class string class

Source: Internet
Author: User
Tags array to string


String: Is a string of data consisting of more than one character. It can also be seen as a character array.
By looking at the API, you can know
A: The string literal "abc" can also be seen as a string object.
B: The string is a constant, and once assigned, it cannot be changed.

Construction Method:
Public String (): Empty construct
public string (byte[] bytes): Convert byte array to string
public string (byte[] bytes,int index,int length): Turns a portion of a byte array into a string
public string (char[] value): Convert character array to string
public string (char[] Value,int index,int count): Turns a part of a character array into a string
public string (string original): Convert string constant value to string

Method of String:
public int Length (): Returns the length of this string.

1 Package cn_string1;2  Public classstring_1 {3  Public Static voidMain (string[] args) {4 byte[] Bys = { the,98, About, -,101};//convert a byte array to a string5String S1 =NewString (bys);6System. out. println (S1);7System. out. println (S1.length ());8System. out. println ("------------");9 TenString s2 =NewString (Bys,1,4);//to convert a portion of a byte array into a string OneSystem. out. println (S2); ASystem. out. println (S2.length ()); -System. out. println ("------------"); -  the Char[] ch = {'L','O','V','E','W','h','o'};//Convert a character array to a string -String C1 =NewString (CH); -System. out. println (C1); -System. out. println (C1.length ()); +System. out. println ("------------"); -  +String C2 =NewString (CH,0,4);//turn a part of a character array into a string ASystem. out. println (C2); atSystem. out. println (C2.length ()); -System. out. println ("------------"); -  -String s =" Love";//The most commonly used -System. out. println (s); -System. out. println (S.length ()); inSystem. out. println ("------------"); -  to  + } -  the}

Java11-1 the most common class string class

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.