There are two methods for determining the same in java:
First, use = to directly determine the same, which is suitable for comparison between two variables, one variable and one object.
For example:
int a=3,c=3;Integer b=new Integer(3);System.out.println(a==c);System.out.println(a==b);
Output result:
True
True
Method 2: Use the equals () function to compare two objects, one object, and one variable.
For example:
int a=3;Integer b=new Integer(3);Integer c=new Integer("3");System.out.println(b.equals(a));System.out.println(b.equals(c));Output result:
True
True
As described above, we can only determine whether two quantities are equal. Next we will introduce a function to determine the size of two objects:
It is conpareTo ();
The specific usage is included in the following code:
// Compare public class Main_3 {public static void main (String [] args) {int a = 3, B = 4; System. out. println (a> B); System. out. println (a = B); System. out. println (
<= Integer x = new Integer (4); Integer y = new Integer (6); System. out. println (x> y); System. out. println (x = y); // Why is it not true? System. out. println (x
<== Comparison // If You Want To determine whether two objects are equal, you can use the equals () function System. out. println (x. equals (y); // if you compare the sizes of two objects, you can use the compareTo function. // the return value of this function is the int type value System. out. println (x. compareTo (y); // returns 0 to indicate that the x object is equal to the y object, and returns-1 to indicate that x is less than y, returns 1, indicating that x is greater than y. // compare the object with the basic type. System. out. println (x = B); System. out. println (x. equals (B ));}}