KnowledgeBoat Logo
|

Computer Applications

Predict the output.

int res = Integer.valueOf("100").compareTo(new Integer(100)); 
System.out.println(res);

Java

Java Library Classes

6 Likes

Answer

0

Working

Here, Integer.valueOf("100") returns an Integer object storing 100 and new Integer(100) creates a new Integer object with the value 100.

Integer.compareTo() compares two Integer objects numerically, after auto-unboxing is performed by the compiler and the Integer objects are converted to integer type values. The function compareTo() returns 0 as primitive values of both the objects are equal.

Answered By

6 Likes


Related Questions