LDNDeveloper

Andrew Pallant

     Senior IT Executive 


Donate To Support My Blog Donate if this post helped you. Coffee money is always welcomed!




String Comparison using Equals

Physical Link: String Comparison using Equals


s.equals(x);

Will return true if the strings s and x contain the same character sequence. So:

String s = new String(“foobar”);
String x = new String(“foobar”);

Then s.equals(x) will return true, but s == x will be false, because s and x are not the same String Object.

If you then do:

String y = s;
String t = x;

You have a case where any string of the 4, .equals() any other string of the 4 (s, t, x, y) will return true, but only s == y or t == x will return true. That is because they refer to the same object.

The post String Comparison using Equals appeared first on LDNDeveloper.

Author:
Categories: Uncategorized


©2024 LdnDeveloper