First, String introduction (reference type)
The 1.java.lang.string string.
A string that is enclosed in "" can be seen as an instance of implementing this class.
There are also many simple methods in the class string
2. Features
1). String invariant: The value of a string cannot be changed after it is created
2). Because the string object cannot be changed. All they can be shared
3). (The underlying is so implemented) to string S1 assignment "abc" is equivalent to char[] data = [' A ', ' B ', ' C ']
3. Construction examples (interview may be asked,)
Non-parametric construction
String str = new string ();
Constructed from a character array
Char chars[] = {' A ', ' B ', ' C '};
String str2 = new string (chars);
Constructed from a byte array
byte b[] = {97,98,99};
String str3 = new string (b);
4. String comparisons (ask during interview, with String to understand)
1.== comparison
1. The basic type of this thing can be compared to the basic type of four types of eight (comparison is the value is equal)
2. Compare address values when comparing reference types
2.equals (String str)
Same content, return True
5.String method
(1) Get
Equalsignorecase (String str) ignores case comparison content
Intlength () returns the string length
Stringconcat connect the specified string to the end of the string
Charcharat (int index) returns the char value at the specified index
int indexOf (String str) returns the position (index) of the first occurrence of the string specified by the string, which is the corresponding first-time index, and returns 1 if it is not found.
string substring (int beginindex) returns a string, starting from Beginindex to intercept the string to the last
string substring (int beginindex, int endIndex) returns a string, starting from Beginindex to intercept the string
To Endindex to intercept the string. Contains beg without end
(2) Conversion
1.String replace ()
Ex
String str = "ABBCCD"
String newstr = str.replace (' B ', ' * ')
System.out.println (NEWSTR)
A**ccd
This will replace all B-containing
String newstr = str.replace ("BB", "*")
Operation result is A*CCD
2.
char [] chars = ToCharArray () turns into a character array
3.
Byte[] GetByte (); uses the default character set of the platform to encode the string into a new byte array.
4. string[] Split (String regex) "\ \." Express. Escape.
To split a string with a regex
Java Learning string