Linked Questions

5 votes
3 answers
800 views

Integer comparison in Java is tricky, in that int and Integer behave differently. I get that part. But, as this example program shows, (Integer)400 (line #4) behaves differently than (Integer)5 (line ...
abelenky's user avatar
  • 65k
-1 votes
1 answer
56 views

as far as I understand due to Java autoboxing I can do this: Integer i = 10; Integer j = 10; boolean b = i == j; Or this: int ii = 10; int jj = 10; Integer i = ii; Integer j = jj; boolean b = i == j;...
mmong's user avatar
  • 64
210 votes
8 answers
70k views

class D { public static void main(String args[]) { Integer b2=128; Integer b3=128; System.out.println(b2==b3); } } Output: false class D { public static void main(...
vipin k.'s user avatar
  • 2,735
27 votes
7 answers
218k views

I'm a newbie Java coder and I just read a variable of an integer class can be described three different ways in the API. I have the following code: if (count.compareTo(0)) { System.out....
phill's user avatar
  • 14k
12 votes
6 answers
27k views

Map<String,Integer> m; m = new TreeMap<String,Integer>(); Is it good practice to add the following cast just to avoid the null pointer exception when m.get() is null. System.out.println( (...
Andrew G's user avatar
  • 2,625
11 votes
5 answers
14k views

The following code seemed really confusing to me since it provided two different outputs.The code was tested on jdk 1.7. public class NotEq { public static void main(String[] args) { ver1(); ...
Debadyuti Maiti's user avatar
3 votes
3 answers
1k views

I know that i am comparing reference while i'm using == which is not a good idea but i did not understand why is this happening. Integer a=100; Integer b=100; Integer c=500; Integer d=500; System.out....
Hiren's user avatar
  • 1,445
2 votes
5 answers
508 views

As we know that == in case of Objects returns true if pointing to the same reference else it returns false. So , if i have taken Integer a = new Integer("1"); // Creating Integer Object a ...
Vaibhav Jain's user avatar
-2 votes
2 answers
322 views

I know int range is -2147483648 to +2147483647 but here I'm getting output as true and false. Why? Actually i1 and i2 point to the same object, so output is true. I can understood but i3 and i4 also ...
Mahi's user avatar
  • 1
0 votes
4 answers
126 views

This is classical, but writing to Google did not give me hits. My code: Integer i = ..; // Sth is put from database. if (i != 1) { // do sth } else { // do not. } Case: I know that this ...
mico's user avatar
  • 12.7k
0 votes
0 answers
38 views

"Birthday Cake Candles" is the name of this problem in HackerRank This is the working code and if I replace "int" with "Integer" it is not working. It is working for all ...
HelpMe's user avatar
  • 1