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

  1. Serializable, implemented serialization
  2. Comparable, which makes String implement the compareTo method
  3. CharSequence, which enables String to implement methods such as length, charAt, etc
  4. Char [] value, used to store the value of a String
  5. 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:

  1. First match the string that’s passed, new a new set
  2. While (true) matches
  3. 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