Skip to content

Instantly share code, notes, and snippets.

@captswag
Created July 10, 2017 05:57
Show Gist options
  • Save captswag/81d59f9e9b0b25c522e957280d72cbe0 to your computer and use it in GitHub Desktop.
Save captswag/81d59f9e9b0b25c522e957280d72cbe0 to your computer and use it in GitHub Desktop.
/**
* Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
* Parameters:
* anObject The object to compare this String against
* Returns:
* true if the given object represents a String equivalent to this string, false otherwise
* See also:
* compareTo(java.lang.String)
* equalsIgnoreCase(java.lang.String)
*/
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String anotherString = (String)anObject;
int n = count;
if (n == anotherString.count) {
char v1[] = value;
char v2[] = anotherString.value;
int i = offset;
int j = anotherString.offset;
while (n-- != 0) {
if (v1[i++] != v2[j++])
return false;
}
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment