String Comparison using EqualsPublished: Feb 23, 2011 15:14:00
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.
Author: Andrew Pallant