Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collection classes

 
Marcelo Ortega
Ranch Hand
Posts: 528
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Priya Jothi
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 528
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Priya.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic