Differences about "==" and "equals"

xiaoxiao2021-03-05  28

Simply put in the same value, but the same and different distinction, for example,

Public class test {public static void main (string [] args) {test a = new test (); system.out.println (a.isright ()); system.out.println (a.sswrong ());} Public boolean isright () {string str1 = "abc"; string str2 = "abc"; if (str1.equals (str2)) return true; returnlean iswrong ()} public boolean iswrong () {string str1 = new string ("ABC "); String str2 = new string (" abc "); if (str1.equals (str2)) return true; returnaf false;}}

Print Result true, True If you replace Equals to "==", the result is true, false

转载请注明原文地址:https://www.9cbs.com/read-34352.html

New Post(0)