What is the difference between == and the equals?

Compare all basic types can only use ==, compare the results you see will be equal to the literal equivalent, what is the basic type? Byte, short, int, long , char, float, double these types are the basic types basic types not an object so there is no comparison with equals.
any comparison of reference types (objects), == is the comparison of two references is not the point to the same memory address , equals to compare two references are literal is not the same, what is the word ? can you see the face value of value is the literal, for example: String s = "abc"; abc is literal.
the basic types of packaging type is an object type, so unless two of the same literal references point to the same memory address , value will be equal to, for example:
Integer a = new Integer (3); Integer b = a; // assign each other
so that an equal sign or equals comparisons will come true, remember that two references who are used to initialize the new the results that will only == comparison is false, between each other with the assignment, the comparison result is true.
relatively well understood point:
String a = "abc";
String b = "abc";
a == b a.equals and (b); will result is true, since no new objects to a new, in fact, a and b Points to a String object with "abc", changed:
String = A new new String ( "ABC");
String String new new B = "ABC");
after == false result is a short reference to the above description. not difficult to understand.

Guess you like

Origin www.cnblogs.com/sttcorcy/p/11652570.html