Can anyone tell me why the if statement never passes please. I have put the lines that are shown in the terminal window under the code. (the System.out.println() )
The bottom two System.out's are just a test to see if they are changing and they do but the if statement doesn't see they are the same.
Code:
int listPosition = 0;
while(listPosition < basket.size())
{
Item item;
item = basket.get(listPosition);
if(itemName.toLowerCase() == item.getName().toLowerCase())
{
basket.remove(listPosition);
System.out.println(itemName + " Removed");
}
else
{
System.out.println("Error");
System.out.println();
}
System.out.println(itemName.toLowerCase());
System.out.println(item.getName().toLowerCase());
listPosition++;
}
Terminal window shows this:
Code:
Error
apples
apples
So they are the same and the toLowerCase is working but for some reason the if statement doesn't see them as the same, why is this?
Thanks
Ash