Computer Applications
Predict the output.
int res = Integer.valueOf("100").compareTo(new Integer(100));
System.out.println(res);
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.
Related Questions
Which methods return primitive values from Wrapper class objects?
Which methods return Wrapper class objects from primitive values ?
Find the error:
Integer obj = new Integer("A"); System.out.println(obj);Find the error :
double n2 = Double.parseDouble("2"); double n3 = Double.parseDouble("OCA"); System.out.println(n2 + " " + n3);