I am very sure that the following code should print "YES". But it prints "NO". Is it because of the 10^9 value? When I do the same code with int[] arr, it prints "YES" (Expected). Only ArrayList<>() behaves differently. Any help is really appreciated. Thanks.
import java.io.*;
import java.util.*;
class Solution {
public static void main (String[] args) {
int x = 1000000000;//1e9
int y = 1;
int z = 1000000000;//1e9
List<Integer> list = new ArrayList<>();
list.add(x);
list.add(y);
list.add(z);
Collections.sort(list);
if(list.get(1) != list.get(2))
System.out.println("NO");
else
System.out.println("YES");
}
}