Java implementation of the compareTo and equals methods
KW.java
class KW
{
    public static void main(String args[])
    {
        Integer a=1;
        System.out.println(a.compareTo(0));
        System.out.println(a.compareTo(1));
        System.out.println(a.compareTo(2));
        System.out.println(a.equals(1));
        System.out.println(a.equals(0));
        System.out.println(a.equals(2));
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW 1 0 -1 true false false kodingwindow@kw:~$
Advertisement