Thursday 25 July 2013

Quick overview of collection concepts

Collection

collection - represents any data structures in which objects are stored and can be iterated.
Collection-which is actually the java.util.Collection interface from which Set, List, and Queue extend.
Collections-is the java.util.Collections class that holds a pile of static utility methods for use with collections.

LIST Interface-It provides ordered collection of elements.But it can contain duplicate elements.
ArrayList - A growable array. it is an ordered collection (by index), but not sorted.
Vector - Same as an ArrayList, but Vector methods are synchronized for thread safety.
LinkedList - LinkedList is ordered by index position, like ArrayList, except that the elements are doubly-linked to one another. Good for implementing stack and queue.


SET Interface- A Set cares about uniqueness—it doesn't allow duplicates.
HashSet - unsorted, unordered Set.
LinkedHashSet - A LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements.
TreeSet - The TreeSet is one of two sorted collections (the other being TreeMap).


MAP Interface- A Map cares about unique identifiers. You map a unique key (the ID) to a specific value, where both the key and the value are, of course, objects.
HashMap - The HashMap gives you an unsorted, unordered Map. allows one null key and multiple null values in a collection.
Hashtable - Hashtable is the synchronized counterpart to HashMap. Hashtable doesn't let you have anything that's null.
LinkedHashMap - maintains insertion order (or, optionally, access order). Although it will be somewhat slower than HashMap for adding and removing elements, you can expect faster iteration with a LinkedHashMap.
TreeMap - It is a Sorted Map.


equals() method-
The equals() method in class Object uses only the == operator for comparisons, so unless you override equals(), two objects are considered equal only if the two references refer to the same object.
x.equals(y) == true => x.hashCode() == y.hashCode() [Required]
x.hashCode() != y.hashCode() => x.equals(y) == false [Required]


java.util.Comparator Interface -The Comparator interface gives you the capability to sort a given collection any number of different ways.
java.lang.Comparable Interface-The Comparable interface is used by the Collections.sort() method and the java.util.Arrays.sort() method to sort Lists and arrays of objects, respectively. To implement Comparable, a class must implement a single method, compareTo().

No comments:

Post a Comment