1. The relational operator generates a Boolean result. They evaluate the relationship between the operands ' values. If the relationship is true, the relational expression generates true (True), and False (false) if the relationship is not true.
1. Check if the objects are equal (= = or! =)
integer n1 = new integer (Integer n2 =); new integer (47); System.out.println (N1 == N2); //result is falseSystem.out.println (n1 != n2 ); //result is true because = = and! = are the handles of the comparison object, N1 and N2, although the integer object is the same, the object content is the same, but the handle differs 2. equals () using the integer n1 = new integer (+); Integer n2 = new integer (47); System.out.println (N1.equals (N2)); //tureequals compares object content, so ture;class value { Int i;} Public class equalsmethod2 {public static void main (String[] args) { Value n1 = new value (); Value n2 = new value ();n1.i = n2.i = 10; System.out.println (N1.equals (N2)); //false}} The results are now back to false! This is because the default behavior of equals () is to compare handles. So unless you change the Equals () in your new class, it's impossible to show the behavior we want.
This article is from the "12380959" blog, please be sure to keep this source http://12390959.blog.51cto.com/12380959/1909179
Java Relational operators