String substring method & equals with ==

       String constant pool
The difference between equals and == in Java

All classes in JAVA are inherited from the Object base class. An equals method is defined in the base class in Object. The initialization behavior of this method is to compare the memory address of the object, but this method is overridden in some class libraries. Gone, for example, equals in String, Integer, Date has its own implementation, instead of comparing memory addresses!!! 

It is best to use equals to compare the values ​​of the wrapper classes of basic data types. When comparing with " == ", if the data is out of range (int type is -128 to 127), even if the values ​​are equal, it will be false.
Difference between Integer and int

1. Integer is the encapsulation class provided by int, and int is the basic data type of Java ;


2. The default value of Integer is null, and the default value of int is 0;


3. Variables declared as Integer need to be instantiated, while variables declared as int do not need to be instantiated;


4. Integer is an object, and a reference is used to point to this object, while int is a basic type, which directly stores values.


There are two substring methods of the String type :

   String.substring(a,b) means starting from position a and ending at position b;

   String.substring(a) means starting from position a.


// reference data type == compares whether two reference variables point to the same object
    // literal: " abc
"
    // Difficulty is not important
    // Basic data types have their own constant pool

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325203033&siteId=291194637