Created
July 10, 2017 05:57
-
-
Save captswag/81d59f9e9b0b25c522e957280d72cbe0 to your computer and use it in GitHub Desktop.
Original Java source code for equals() method. (http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/String.java#String.equals%28java.lang.Object%29)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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