Array.binarySearch() oOnly usable on sorted array! OOtherwise,result unpredictable o If there are multiple elements equal to the specified object,there is no guarantee which one will be found. ●Return: OLocation if find the key (positive number) O(-(insertion point)-1)if not find key (negative)
Array.binarySearch() lOnly usable on sorted array! ¡Otherwise, result unpredictable lIf there are multiple elements equal to the specified object, there is no guarantee which one will be found. lReturn: ¡Location if find the key (positive number) ¡ (-(insertion point) - 1) if not find key (negative)
search example:compareExp.java
search example: compareExp.java
Collection:hold one item at each location List:items in order Set:no duplicates,no ordering ArrayList List LinkedList Vector Collection Preserve the insertion of the elements Set HashSet LinkedHashSet TreeSet
Collection List ArrayList LinkedList Vector Set HashSet LinkedHashSet TreeSet Collection: hold one item at each location List: items in order Set: no duplicates, no ordering Preserve the insertion of the elements
Map:key-value pairs,fast retrieval no duplicate keys,no ordering HashMap LinkedHashMap Map Hashtable Preserve the insertion of the elements TreeMap
Map HashMap LinkedHashMap Hashtable TreeMap Map: key-value pairs, fast retrieval no duplicate keys, no ordering Preserve the insertion of the elements