the UML diagram are very clear on this page.
The Java JDK contains two high level Interfaces:
- java.util.Collection
- java.util.Map
java.util.Collection
interface. The Collection interface has three sub interfaces.- java.util.Set
(implementation are TreeSet,HashSet ...) Set
cannot have duplicates in it.- java.util.List
- ( implementation are Vector,Stack,ArrayList,LinkedList,AttributeList,RoleList...)
- interfaces SortedSet
- java.util.Queue
( implementation are: PriorityQueue, ArrayBlockingQueue ..) interface: BlockingQueque
java.util.Map implementations are:
TreeMap,HashMap, HashTable,LinkedHashMap,IdentityHashMap ..
Before selecting a particular collection implementation, ask the following question:
- Can my collection contain the same elements, i.e. are duplicates allowed?
- Can my collection contain the
null
element? - Should the collection maintain the order of the elements? Is the order important in any way?
- How do you want to access an element? By index, key or just with an iterator?
- Does the collection need to be synchronized?
- From a performance perspective, which one needs to be faster, updates or reads?
- From a usage perspective, which operation will be more frequent, updates or reads?
No comments:
Post a Comment