Edit: Some people stated that this is possible duplicate of one of question asking how to compare string values. I was asking about comparing double with int, that is why .equal() did not work.
First, I set a LinkedList of doubles with first element = -999
then if the comparison is
return listOfNumber.getFirst().equals(-999);
the outcome will be false.
However if the comparison is written as
return listOfNumber.getFirst()== -999;
Then the outcome will be true.
I thought .equals() compares the value and == compare the object and == can only take -128 to 127. So why exactly I cannot use .equals to compare doubles?
Also if the LinkedList is String with first element = "a" if I use
return ListOfString.getFirst() == "a";
then the outcome is false but if I use
return ListOfString.getFirst().equals("a");
then the outcome is true.
I am very confused why the comparison of double and string need to be different to yield correct result?