Iterator collection over Iterator vs For-each
Only Iterator can modify the collectionIterator vs ListIterator
- Iterator travel only forward. ListIterator both side
- Iterator can use on List, Set, Queue but ListIterator only List
ArrayList vs Vector
- Vector is synchronized and ArrayList not
- Vector increase its size by doubling, ArrayList in 50%
ArrayList vs LinkList
- ArrayList use a dynamic array, LinkList use doubly linked list
- ArrayList Fast store and fetch data, LinkList efficient manipulation
ArryList read past
LinkList list item modify fast
Set
HashSet Use has map (hashCode()) need to implement hashCode() and equals() //hashcode Ojbject.hash(,,)
TreeSet Use tree Map ordered
EnumSet
HashSet vs TreeSet
HashSet - no order , TreeSet - ascending order
HashMap vs HashTable
- HashTable synchronized HashMap not
- HashTable can't have null key or value but HashMap can
Collection vs Collections
- Collection is interface and provide normal functionality
- Collections is a class to sort and synchronize collections
Fail-Fast vs Fail Safe Iteration
Fail-Fast - throw concurrent exc - HashMap,Vector, ArrayList, HashSet
Fail-Safe - create a copy when iterator -CopyOnWriteArrayList,
ConcurrentHashMap
No comments:
Post a Comment