I have a simple doubt. Would be great if anyone helps me.
I have two strings:
String string1 = "4"; // and
String string2 = "04";
Both the values are equal but how to compare them in java? We have equals and equalsIgnoreCase for comparing String alpha values, similarly how to compare numeric values.
Integerobjects using==, which might be considered a Crime.neware not 'cached'.Integer a = 1;is not the same asInteger a = new Integer(1);[-128, 127], in which case, it will not create a new Integer object when you assign an integer literal to an Integer reference, as stated bymsi. I was mistaken, Cache doesn't hold tru in your case.==is that, it doesn't really compares the content, rather the value of reference. So, two object reference pointing to two objects having same value will not be judged equal by==, so you should always useequalsmethod for object comparison.