Can you compare chars with ==? [duplicate]
问题 This question already has answers here : What is the difference between == and equals() in Java? (23 answers) Closed last year . For Strings you have to use equals to compare them, because == only compares the references. Does it give the expected result if I compare chars with == ? I have seen similar questions on stackoverflow, E.g. What is the difference between == vs equals() in Java? However, I haven't seen one that asks about using == on chars. 回答1: Yes, char is just like any other