Sunday, January 31, 2016

[Java] Collections



See original image

 Set : non duplication, non order
 List : can duplication, have order
 Map : <key, value> structure


Vector : 
array based (can be replaced by ArrayList)
re-sizable : 2 times re-size,
synchronous

ArrayList : 
array based,
re-sizable:1.5 time re-size, initial  default 10 ,
non-synchronous( solution : Collection.synchronizedList(new ArrayList) )
fast in looking up
slow in inserting and deleting

LinkedList:
linked node based,
fast in inserting and deleting
slow in looking up

HashMap:
non-synchronous
initial size = 16
use linkedlist to resolve collision
can have one null key and several null value

HashSet
non duplication HashMap(based on HashMap)

HashTable
synchronous
cannot have null key or null value

hashCode for domain searching
x.equals(y) == true ---> same Hashcode
x.equals(y) == false ---> hashcode can be same or different

Queue :
add() : add an element or Exception if it's full
remove() : remove and return the first element or Exception

offer() : add an element or return -1 if it's full
poll(): remove and return the first element or return null

put() : add an element or block if it's full


BlockingQueue -> blocking algorithm to realize the thread safty
ConcurrentLinkedQueue -> non-blocking algorithm for thread safty


No comments:

Post a Comment