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