Wierd Problem! Code is not working for values greater than 120

public int removeDuplicates(ArrayList A) {
int i=0;
int j=1;
if(A.size()==1)
{
return 1;
}
while(j!=A.size())
{
if(A.get(i) == A.get(j))
{
A.remove(j);
}
else
{
i++;
j++;
}
}

    return A.size();
}

It’s happening because java has cached instances of low numbered Integer objects but not any of higher valued Integer objects.
Use equals() OR intValue() instead.

Click here to start solving coding interview questions