What will the following code print out?

public class My {
    public static void main(String...args) {
       Integer i1 = new Integer("013");
       Integer i2 = new Integer(013);
       System.out.println(i1 == i2);
       System.out.println(i1.equals(i2));
    }
}
Explanation
Constructors of wrapper classes that take String as an argument consider that String as a decimal number. Therefore i1 = 13, i2 = 11.

P.S. In the first case the result will be false even if numbers are equal, because links to different objects are compared - not their values (objects are not added to the pool when new is used).

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes