I am working through The Art & Science of Jave--An Introduction to Computer Science by Eric S. Roberts. On page 146 he is trying to explain the difference between the equals method and the == operator with a string example. His code snippet example is:
The author points out that the first if statement is checking to see if the string object "yes" is exactly the same as the string answer "yes' that the user may type in. He says that these can never be the same. Instead, the second if statement checks to see whether the value of the program's string object "yes" is the same as the value of the user's inputted string object "yes", which is what I should be checking for. I think I see the author's point, but cannot help but think of the following:
I know that this works, but it is working with one of Java's primitive data types. Do these not count as objects? Would someone help me understand the difference between these two examples?
The author points out that the first if statement is checking to see if the string object "yes" is exactly the same as the string answer "yes' that the user may type in. He says that these can never be the same. Instead, the second if statement checks to see whether the value of the program's string object "yes" is the same as the value of the user's inputted string object "yes", which is what I should be checking for. I think I see the author's point, but cannot help but think of the following:
I know that this works, but it is working with one of Java's primitive data types. Do these not count as objects? Would someone help me understand the difference between these two examples?