All About Java Collection : Useful Point wise information

What Do You Do with a Collection?
  • Add objects to the collection.
  • Remove objects from the collection.
  • Find out if an object (or group of objects) is in the collection.
  • Retrieve an object from the collection (without removing it).
  • Iterate through the collection, looking at each element (object) one after another.
Key Interfaces and Classes of the Collections Framework
  • Collection
  • Set
  • SortedSet
  • List
  • Map
  • SortedMap
  • Queue 
·         HashMap
·         Hashtable
·         TreeMap
·         LinkedHashMap
·         HashSet
·         LinkedHashSet
·         TreeSet
·         ArrayList
·         Vector
·         LinkedList
·         PriorityQueue
·         Collections
·         Arrays
Note : Basically You will find three kinds of collection words in this framework but each has its own importance given as below
i)        collection (lowercase c), which represents any of the data structures in
which objects are stored and iterated over.
ii)       Collection (capital C), which is actually the java.util.Collection interface
 from which Set, List, and Queue extend. (That’s right, extend, not implement. 
There are no direct implementations of Collection.)
iii)     Collections (capital and ends with s) is the java.util.Collections class
that holds a pile of static utility methods for use with collections.

List Interface
  • A List cares about the index.
  • This as a growable array
  • It gives you fast iteration and fast random access
  • It is an ordered collection (by index), but not sorted
  • Vector is a holdover from the earliest days of Java
  • Vector and Hashtable were the two original collections
  • Vector is basically the same as an ArrayList
  • Vector methods are synchronized for thread safety
  • You’ll normally want to use ArrayList instead of Vector because
  • the synchronized methods add a performance hit you might not need
  • Vector is the only class other than ArrayList to implement RandomAccess
  • A LinkedList is ordered by index position, like ArrayList, except that the elements are doubly-linked to one another
  • LinkedList  is best for adding and removing from the beginning or end, which makes it an easy choice for implementing a stack
  • or queue.
  • LinkedList may iterate more slowly than an ArrayList
Set Interface
  • A Set cares about uniqueness—it doesn’t allow duplicates
  • A HashSet is an unsorted, unordered Set
  • It uses the hashcode of the object being inserted
  • Use this class when you want a collection with no duplicates and you don’t care about order when you iterate through it
  • A LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements.
  • Use this class instead of HashSet when you care about the iteration order.
  • When you iterate through a HashSet the order is unpredictable, while a LinkedHashSet lets you iterate through the elements in the order in which they were inserted.
  • The TreeSet is sorted collections
  • It uses a Red-Black tree structure, and guarantees that the elements will be in ascending order, according to natural order
  • TreeSet, lets you define a custom sort (your own rule to sort) order via a Comparable or Comparator)
Map Interface
  • A Map cares about unique identifiers
  • The HashMap gives you an unsorted, unordered Map
  • A Map cares about unique identifiers.
  • You map a unique key (the ID) to a specific value
  • Map implementations let you do things like search for a value based on the key
  • Like Vector, Hashtable has existed from prehistoric Java times
  • Looks HashMap vs. Hashtable. Where’s the capitalization of t?
  • Hashtable is the synchronized counterpart to HashMap
  • Hashtable are synchronized,  means that the key methods of the class are synchronized
  • HashMap lets you have null values as well as one null key, a Hashtable doesn’t let you have anything that’s null.
  • LinkedHash-Map collection maintains insertion order
  • It will be somewhat slower than HashMap for adding and removing elements,
  • Iteration with a LinkedHashMap will be faster
  • TreeMap is a sorted Map by natural order
  • Like TreeSet, TreeMap lets you define a custom sort order via a Comparable or Comparator
Queue Interface
  • A Queue is designed to hold a list of “to-dos,” or things to be processed in some way.
  • We PriorityQueue is to create a “priority-in, priority out” queue as opposed to a typical FIFO queue
  • A PriorityQueue’s elements are ordered either by natural ordering (in which case the elements that are sorted first will be accessed first) or according to a Comparator
  • In either case, the elements’ ordering represents their relative priority

About rajkirpal

i am a software engineer. and i have decent knowledge about java technologies like ANDROID, Servlet, Jsp, Struts, Hibernet, Spring, J2ME, Java Script, Ajax, JQuery, CSS. Further i am Preparing Easy understandable materials/documents upon the same java technologies and developing project in core java , advanced java and j2me , ANDROID as per the requirements Also designing the web sites and logos Thank You.
This entry was posted in J2SE. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s