Document directory
String class:
Public BooleanEquals(Object anobject) overload the equals method of the object
-
Compares this string to the specified object. The result is
trueIf and only if the argument is not nullAnd is StringObject that represents the same sequence of characters as this object.
Public intHashcode() The hashcode method of the object is also overloaded.
-
Returns a hash code for this string. The hash code for
StringObject is computed
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
UsingintArithmetic, wheres[i]IsITh character of the string,nIs the length of the string, and^Indicates exponentiation. (The Hash Value of the empty string is zero .)
However, stringbuffer does not overload the equals and hashcode methods. Therefore, when calling these two methods, we still use the methods in the object class. Therefore, even if the content of the two stringbuffer is the same, the hashcode may also be different.
File class:
Compareto
public int compareTo(File pathname)
-
Compares two abstract pathnames lexicographically. The ordering defined by this method depends upon the underlying system. On Unix systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.
Equals
Public BooleanEquals(Object OBJ) reloads the object method.
-
Tests this abstract pathname for equality with the given object. Returns
trueIf and only if the argument is not nullAnd is an abstract pathname that denotes the same file or directory as this abstract pathname. whether or not two abstract pathnames are equal depends upon the underlying system. on UNIX systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.
Hashcode
Public intHashcode() The object method is reloaded.
-
Computes a hash code for this abstract pathname. because priority ity of abstract pathnames is inherently system-dependent, so is the computation of Their hash codes. on UNIX systems, the hash code of an abstract pathname is equal to the exclusive OrOf the hash code of its pathname string and the decimal Value
1234321. On Microsoft Windows systems, the hash code is equal to the exclusive OrOf the hash code of its pathname string converted to lower case and the decimal Value 1234321. Locale is not taken into account on lowercasing the pathname string.
Therefore, create an object for a file and its copy. The hash values of these two objects may be different because they are related to the path, it does not mean that these two files are different (this refers to the file content). If hash software or MD5 software is used to calculate the hash values of these two files, it should be the same