SCJP 1.6版考題 186

出自 陳富國維基館
於 2013年3月30日 (六) 00:32 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: 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 tha...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
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.

解答


Ans: C E

解說:

對hashCode方法…
The hashCode method for a given class can be used to test for object inequality, 
but NOT object equality, for that class.
雜湊值可用在測試物件的不等性,不能用來測試物件的相等性
 (因為雜湊值不同,物件必不同,湊值一樣,物件未必一樣,因為不同的物件有可能雜湊值一樣)

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.
hashCode方法被java.util.HashSet collection類別用來將元素以雜湊槽方式聚集起來以迅速取出物件.