Andrew Pallant

Software & Web Developer

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


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 Software Developer In London.

Categories: Uncategorized

Google | humanstxt.org | Andrew Pallant's Blog Site
©2017 LdnDeveloper