Which
two statements are true about the hashCode method? (Choose two.)
A. The hashCode method for a given class can be used to test for object equality and object inequality for that class.
B. The hashCode method is used by the java.util.SortedSet collection class to order the elements within that set.
C. The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class.
D. The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution.
E. The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.
答案:CE
參考:12-4 各種集合的特色
--------------------------------------------------
C. hashCode檢查兩各物件是否不相同, 如果可能相同再用equals檢查是否相同.
E. hashCode用來幫助hashset增加存取速度.
沒有留言:
張貼留言