aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Collection classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Collection classes" Watch "Collection classes" New topic
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Collection classes