String comparison with logical operator in Java

前端 未结 7 1130
别那么骄傲
别那么骄傲 2020-12-03 23:59

When comparing two strings, I was taught that we shouldn\'t use the logical operator (==). We should use String.equals(String) for the comparison. However, I see that the fo

7条回答
  •  孤街浪徒
    2020-12-04 00:27

    The == operator is used to check if both are references to the same String object while .equals compares the values.

提交回复
热议问题