1. String:
A. Classification: String, StringBuffer, StringBuilder
B. Special: ①string is the only reference data type that can be assigned directly with a constant value
The constant of ②string is also an object (that is, "Hello" is also an object)
③string object content is immutable!!!
④ because of the existence of ③, resulting in string concatenation of strings, there will be a large consumption, and StringBuffer, StringBuilder is used to solve the problem of the string content is not variable
⑤ is specifically overloaded with the "+" operator in Java for string concatenation
C. Memory: Java pair string constants are preloaded during the load period, resulting in a string constant pool of data segments. When running, if you want to use a string constant, simply remove it from the constant pool.
2.String array-related methods:
Str.lengtn () ///str string length str.tochararray () // str into char[] Array Str.charat (2) // take the character str.indexof (' e ') corresponding to the subscript position returns the index of the first occurrence of a character in string, no return-1 str.lastindexof (' e ') // returns the index of the last occurrence of a character in a string that does not appear return-1
3.String letter-related methods:
STR3 = Str.touppercase () // get a new all-uppercase new string STR3 = str.tolowercase () // get a new all-lowercase new string "Yes". Equalsignorecase ("yes") // ignore case to compare "yes". CompareTo ("no") // in dictionary order (get the difference of the first different aism value, if each is the same, the comparison length is poor)str0.comparetoignorecase (str1) // ignore case, dictionary order comparison
4.String methods related to content manipulation:
str2 = str.replace (' A ', ' a ')//Replace a substring in str with another stringSTR3= Str.replace ("ll", "")//Ibid .Str.endswith ("Lo")//determine what the string ends withStr.startswith ("H")//determine what the string starts withSTR4= Str.substring (0,3)//Intercept string according to subscript position [front closed, rear open]STR4= Str.substring (3)//intercept the string to the end position according to the subscript positionSTR6= Str.concat ("World")//string connection, equivalent to "+" number
The three most important methods of 5.String
A. Trim ()--Remove the space before and after the string
★ As long as you receive the external input string, you should call Trim () By default to remove the invalid space before and after the string, and then perform subsequent operations
B. Split ()--do a string split according to the specified delimiter
String birthday = "1992-2-14"= Birthday.split ("-");
C. Matches ()--Regular expression validation
① Regular Expression (regex): matching template for string content
② Regular Expression features: the regular expression itself is a string
[] denotes a character, and the bracketed content is the choice of the character.
{} indicates the number of occurrences of the preceding regular expression {m,n} at least-at most {m,} at least-infinity {m} can only
? Equivalent to {1,0} * equals {0,} + equals {1}
() denotes grouping, multiple choice One (m|n) two Select one (m|n|k) three Select one
Common classes of Java (i)