String
The constant pool concept, when the string object is new and is referenced as: string s = new string ("Hello");//It opens an address in the stack, the reference address is in the stack, and the value is stored in the heap;
When string is passed to: string s = new string;s= "Hello";//its address in the constant pool is not equal
The string class is located in the Java.lang package and is rich in methods: calculating the length of a string, comparing strings, connection strings, extracting strings
The. Touooercase () string is converted to uppercase;. toLowerCase () returns a lowercase string;. equalsignorecase (), to determine ignoring case
. concat s = s.concat (' xxxx ') string concatenation, S + = ' xxxx ' can also realize the concatenation of strings;
. Contains ("X") determines whether the string contains X and returns a Boolean value;
. IndexOf () The position of the first occurrence; LastIndexOf () the last occurrence;
. substring (int a) extracts the contents of paragraph a after;. substring (int a,int b) extracts the contents of items A to B; (Overloading of methods)
. Trim () Returns a copy that does not contain any space characters before or after
. Split () intercepts a character and separates it into a new array;
. ToCharArray () string into a character array
Stringbuffer:string Enhanced Version
Reference data types require a new build object, StringBuffer sb = new StringBuffer ()
Assigning values to objects (adding characters)
Data processing
Use complete, set length=0;
. toString (); Convert to String type
. Append ("xxx") Append string
. insert (int A, "x") A is the position that needs to be added to the subscript a, and X is a string that can add data of any data structure
. Recerse () string content upside down
. Delete (start, end) deletes from the start position to the end position;
. replace (start, End, "X") replaces the start position to the end position with X
. replace ("a", "X") replaces all of a with x;
. SetLength () Sets the length of the string, typically used for word Fu Qing 0, to free up memory space
Some common methods of JAVA String and StringBuffer