An overview of strings in Java
1, the string can be considered a character array
2, which is also a constant, cannot be changed once defined. stored in a string constant pool.
Prototype: Public final CALSS String extends Object implements Serializable,compareable,charsequence
String s = "abc"; Equivalent to
char[] data = {' A ', ' B ', ' C '};
string s = new String ("abc");
The common construction method is
public string ();p ublic string (byte[] bytes);p ublic string (byte[] bytes,int offset,int length);
Starting from the offset index of the byte[] array, length, string
Public String (char[] value)
Convert a character array to a string
Public String (char[] value,int offset,int length)
Converts a character array from offset to a string of length
public string (string original)//create a copy of string original
Method: public int length (); Returns the length of a string
The string can be spliced with any data, and then a new string is generated.
For example:
String S1 = "ABCDE";
int a = 100;
BYTE B = 101;
char C = ' F ';
String s2 = s1 + A;
String S3 = S1 + b;
String S4 = S1 + C;
System.out.println ("s2 =" + s2); The result is abced100
System.out.println ("s3 =" + S3);//result is abcde101
System.out.println ("s4 =" + S4); The result is abcdef
This article is from the "Homecoming" blog, make sure to keep this source http://firrty.blog.51cto.com/4028329/1729722
Java string definition and construction methods