Collections

Typical Collections Hierarchy is as below
In the Collections Framework, the interfaces Map and Collection are distinct with no lineage in the hierarchy. The typical application of map is to provide access to values stored by keys. When designing software with the Collection Framework, it is useful to remember the following hierarchical relationship of the four basic interfaces of the framework.
  • The Collection interface is a group of objects, with duplicates allowed.
  • Set extends Collection but forbids duplicates.
  • List extends Collection also, allows duplicates and introduces positional indexing.
  • Map extends neither Set nor Collection

Interface
Implementation
Historical
Set
HashSet



TreeSet






List



ArrayList



LinkedList
Vector
Stack
Map
HashMap



Treemap



Hashtable
Properties


  • How to sort an Arraylist? How to make it synchronized?

Collections.sort(arrayList);
For syncronizing arraylist we can convert arraylist to Vector.



  • What is iterator?

The iterator() method of the Collection interface returns and Iterator. An Iterator is similar to the Enumeration interface, Iterators differ from enumerations in two ways:
1.Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
2. Method names have been improved.


boolean
hasNext()
Returns 
true if the iteration has more elements.
 Object
next()
Returns the next element in the iteration.
 void
remove()
Removes from the underlying collection the last element returned by the iterator (optional operation).
  • The TreeMap class stores the keys rather than the values in sorted order

Comments

Popular posts from this blog

jQgrid reload with new data

Introduction to jQgrid

Rich Client based UI technologies- A Comparison of Thick Client UI tools