List<Integer> test = List.of(955, 955);
if (test.get(1) == test.get(0))
...
Above condition results in false
List<Integer> test = List.of(955, 955);
int a = test.get(1);
int b = test.get(0);
if (a == b)
...
The above condition returns true.
Why is that the case? What is the difference between the snippets?
In one case, you're comparing two
Integerobject references. In the other case, you're comparing twoints. When using the==operator to compare object references, it will returnFalseif they are not the same object, even if they do wrap the same value.