Menu
Topics Index
...
`


Collections Framework >
Siva Nookala - 14 Apr 2016
As discussed in the previous topics, Collections are a powerful way of managing the data and for manipulating the data. They come handy to developers for solving complex problems easily, since he can focus on the business logic, than trying to do memory management and boundary checks.

The Java collection framework is very powerful and includes numerous capabilities such as cloning, return values, removing elements, and more. The following table summarizes the principal classes in Java collections framework for quick reference:
Principal collection class Base class Base interfaces Allow duplicate elements? Ordered? Sorted? Thread-safe?
ArrayList<E> AbstractList<E> List Yes Yes No No
LinkedList<E> AbstractSequentialList<E> List<E>;
Deque<E>
Yes Yes No No
Vector<E> AbstractList<E> List<E> Yes Yes No Yes
HashSet<E> AbstractSet<E> Set<E> No No No No
LinkedHashSet<E> HashSet<E> Set<E> No Yes No No
TreeSet<E> AbstractSet<E> Set<E>;
NavigableSet<E>;
SortedSet<E>
No Yes Yes No
HashMap<K, V> AbstractMap<K, V> Map<K, V> No No No No
LinkedHashMap HashMap<K, V> Map<K, V> No Yes No No
Hashtable<K, V> Dictionary<K, V> Map<K, V> No No No Yes
TreeMap<K, V> AbstractMap<K, V> Map<K, V>;
NavigableMap<K, V>;
SortedMap<K, V>
No Yes Yes No
From this table we can conclude the following characteristics of the main collections in Java Collection Frameworks:
  • All lists allow duplicate elements which are ordered by index.
  • All sets and maps do not allow duplicate elements.
  • All list elements are not sorted.
  • Generally, sets and maps do not sort its elements, except TreeSet and TreeMap – which sort elements by natural order or by a comparator.
  • Generally, elements within sets and maps are not ordered, except for: LinkedHashSet and LinkedHashMap have elements ordered by insertion order.
  • TreeSet and TreeMap have elements ordered by natural order or by a comparator.
  • There are only two collections are thread-safe: Vector and Hastable. The rest are not thread-safe.

0
Wrong
Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.