There’s really nothing to talk about, so why don’t we just talk about String
Basic introduction
The String String is actually pretty common, and if you’re not new to code, I think it’s probably the most common thing you’ve ever used
The internal structure
Take a look at the main structure of the class
- Serializable, implemented serialization
- Comparable, which makes String implement the compareTo method
- CharSequence, which enables String to implement methods such as length, charAt, etc
- Char [] value, used to store the value of a String
- Hash: Stores the hash value of the value
Commonly used method
A constructor
ToString
The toString method is not a String method, but it is one that most classes implement to convert strings, for example: Integer toStringConverts the value of Integer to a char array, and then calls the String constructor
Spilit
Specific implementation steps:
- First match the string that’s passed, new a new set
- While (true) matches
- When a match is found, it is cut, and then ToString() is stored in the original collection
subString
After a series of checks, the current String is returned if the length is zero, or a new String is called if the length is not
length
Returns the length of the array storing the value
equals
If the value is Object, it checks whether the Object is a String or not. If so, it compares two char arrays of strings. If either of them does not wait, it returns false
compareTo
Returns the difference in the length of the following two strings if each character in the preceding part of the string is identical. Returns the difference in the length of the ASCII characters if each character in the preceding part of the string is different