| Author |
Collection classes
|
Marcelo Ortega
Ranch Hand
Joined: May 31, 2005
Posts: 519
|
|
Can someone please confirm my assumption: List: ArrayList = Fast iteration / slow if there will be alot of insertion and deletion (does this use FIFO (First In First Out) ?). Orderd (by index) but not sorted. Vector = Thread saftey, therefor fast iteration but slower than ArrayList. Orderd not sorted. LinkedList = Fast insertion and deletion, slower iteration than ArrayList and Vector. Orderd by index. Set: HashSet = Unique, no orders. Fast iteration if the hashCode method is eficiently implemented. Slower insertion and deletion. LinkedHashSet = Fast insertion and deletion if the hashCode method is eficiently implemented, slower iteration, uses FIFO, not orderd. TreeSet = Slower iteration and deletion (uses tree structure), uniquenes and sorted by natural order (unless supplied a comparable implementation) Map: HashMap = Uses Key/Value pair, fast iteration if the hashCode method is eficiently implemented, slower insertion and deletion. Hashtable = Practically the same as the HashMap but uses thread saftey methods and allows NO null keys nor values. LinkedHashMap = FIFO, fast insertion and deletion, slower iteration. TreeMap = Sorted by natural order of the Keys, duplicates allowed. Slower iteration and insertion and deletion. Is there any rule of thumb here, i.e: Doubly Linked Lists (LinkedList, LinkeHashSet, LinkedHashMap) are all fast at insertion and deletion but slower at iteration? Please help, my exam is on Thursday.
|
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA
Live life to an interface, not an implementation!
|
 |
Priya Jothi
Ranch Hand
Joined: Jul 13, 2004
Posts: 168
|
|
List: ArrayList = Fast iteration / slow if there will be alot of insertion and deletion (does this use FIFO (First In First Out) ?). Orderd (by index) but not sorted.
Correct.But i dont think it'll use FIFO.It is ordered by index only.Given the index value it'll retrieve value using it.
Vector = Thread saftey, therefor fast iteration but slower than ArrayList. Orderd not sorted.
Correct.
LinkedList = Fast insertion and deletion, slower iteration than ArrayList and Vector. Orderd by index.
Correct.
Set: HashSet = Unique, no orders. Fast iteration if the hashCode method is eficiently implemented. Slower insertion and deletion.
Correct.
LinkedHashSet = Fast insertion and deletion if the hashCode method is eficiently implemented, slower iteration, uses FIFO, not orderd.
Wrong.It is ordered by insertion order or last access order.
TreeSet = Slower iteration and deletion (uses tree structure), uniquenes and sorted by natural order (unless supplied a comparable implementation)
Correct.
Map: HashMap = Uses Key/Value pair, fast iteration if the hashCode method is eficiently implemented, slower insertion and deletion.
Correct.
LinkedHashMap = FIFO, fast insertion and deletion, slower iteration.
Correct.
TreeMap = Sorted by natural order of the Keys, duplicates allowed. Slower iteration and insertion and deletion.
Wrong.Duplicates are not allowed as keys in any type of Map. Juz go thru K&B book and in collections chapter they wud have given a table stating all these types.That'll help you to do well in ur exam in collections. All the best!! Regards, Priya.
|
 |
Marcelo Ortega
Ranch Hand
Joined: May 31, 2005
Posts: 519
|
|
|
Thanks Priya.
|
 |
 |
|
|
subject: Collection classes
|
|
|