I was asked to write down a Java function sharedStr
that by given 2 sorted arrays of String
s, returns the number of String
s that appea
.equals()
(for boolean) or .compareTo()
(for relational comparison) For instance:.
String a = "Hello";
a.equals("Hello"); // true
String b = "Not hi";
b.equals(a); // false
Be careful accidentally using ==
- for constant strings, due to VM designs, it may actually say two Strings are equal, as they are in fact the same object.