• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Collection Class Implementation Features (Contributions Requested)

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am putting together a list outlining the characteristics of the Java Collection implementation classes. I am using a bullet point format to quickly identify the features. Please contribute, keeping the points concise.

-------Collection Class Implementation Features----------

HashSet
�Not ordered
�Allows null
�No Duplicates. Classes must implement equals() and hashCode() for this to work properly.
�Not thread safe


TreeSet
�Ordered ascending by natural order. Classes must implement the Comparable interface
�Can pass Comparator to customize ordering
�No nulls
�Not Thread safe

LinkedHashSet
�Insertion order
�Not thread safe

HashMap
�Null values and keys okay
�Not ordered�
Not thread safe

TreeMap
�Keys ordered ascending by natural order. Classes must implement the Comparable interface.
�Can pass Comparator to customize key ordering
�Not Thread safe

LinkedHashMap
�Not thread safe


ArrayList
�Not Thread safe

LinkedList
�Insertion order
�Used for queues and stacks
�Not thread safe

Vector
�Thread Safe

HashTable
�Thread Safe
�No null keys or values�No Duplicates. Key classes must implement equals() and hashCode() for this to work properly.



--------Collection Interfaces---------

Set


List


Map
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a good tip sheet to keep around. I made one because I can't keep it all in my head. Maybe after a while I'll give you a link to it but I think yours will wind up more comprehensive.

Regarding Lists ... you suggested LinkedList is good for queues and stacks. Maybe you could compare the performance of LinkedList and ArrayList for various operations and show why that is. The JavaDoc gives some pretty good hints. Let us know if that's enough to go on.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A minor correction: it's Hashtable, not HashTable.

It might be noteworthy that classes like Vector and Hashtable are legacy collection classes, which were (more or less) replaced by ArrayList and HashMap in the collections framework of Java version 1.2.

Some interesting background about the collections framework:
Collections Framework Overview
Java Collections API Design FAQ
 
M Burke
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
This is a good tip sheet to keep around. I made one because I can't keep it all in my head. Maybe after a while I'll give you a link to it but I think yours will wind up more comprehensive.

Regarding Lists ... you suggested LinkedList is good for queues and stacks. Maybe you could compare the performance of LinkedList and ArrayList for various operations and show why that is. The JavaDoc gives some pretty good hints. Let us know if that's enough to go on.



Actually, I want something that is consise, not comprehensive. Like you, I just want to be able to keep them all straight in my mind.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by M Burke:

Vector
�Thread Safe



Vector is synchronized, but afaik not thread safe.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HERE is my collections cheat sheet. As noted there, the info came from a Sun newsletter and I just boiled it down to fit in the table. I chose to ignore the "synchronized" attribute of some collections; as Stefan said it doesn't get us all the way to "thread safe" so I synchronize methods that use collections when I think understand threading well enough to believe I need it.
 
M Burke
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's cool, thanks Stan.
 
reply
    Bookmark Topic Watch Topic
  • New Topic