compareTo() Method in java wrapper class Example 2

Java Programming Language / Number Class in java

3211

Program:

 public class WrappercompareTo {
    public static void main (String args[]){

        Integer intObj1 = new Integer (25);
        Integer intObj2 = new Integer ("25");
        Integer intObj3= new Integer (35);
        //compareTo demo
        System.out.println("Comparing using compareTo Obj1 and Obj2: " + intObj1.compareTo(intObj2));
        System.out.println("Comparing using compareTo Obj1 and Obj3: " + intObj1.compareTo(intObj3));

    }

}

Output:

Comparing using compareTo Obj1 and Obj2: 0
Comparing using compareTo Obj1 and Obj3: -1
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.