Java Collection framework

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    4 Favorites

    Java Collection framework - Presentation Transcript

    1. Collection Framework Ankit Kumar Garg    
    2. Introduction to collections  a Collection is a container of Objects, it groups  many Objects into a single one  Arrays are too static (but can be also  considered to be collections)  Arrays have very few built­in features  Originally, Java contained a few collection  classes, like Vector, Hashtable etc.    
    3.  Java 1.2 introduced the Collections Framework  Another example of a collections framework is  the STL(Standard Template Library) in C++.    
    4. What is a Collections Framework  The Java Collections Framework consists of:  Interfaces  –  abstract  data  types  representing  various  collections.  Allow  collections  to  be  manipulated  independently of their implementations.  Implementations  –  these  are  the  concrete  implementations of the interfaces. They are reusable data  structures.    
    5.  Algorithms  –  these  are  able  to  perform  useful  computations,  like  searching  and  sorting,  on  the  implementations  of  the  interfaces.  So,  the  algorithms  are  polymorphic and therefore are reusable functionality.    
    6. Benefits of Collections  Reduces programming effort  Increases program speed and quality  Allows interoperability among unrelated APIs   Reduces effort to design new APIs  Helps to reuse the code    
    7. Interfaces Here are the core Collections interfaces: Note: Collection is at the root, Map is separate All  Collections  interfaces  and  implementation  classes reside in the java.util package.    
    8. Collection interface  add(...) ­ adds an element  contains(...) ­ checks if the specified element  exists  remove(...) ­ removes an element  clear() ­ removes all elements  size() ­ returns the number of elements   toArray() ­ converts the Collection to an array      etc.
    9. Java Collection Classes    
    10. Map classes    
    11. Confusing words  collection (lowercase ‘c’),  which represents any of  the data structures in which objects are stored and iterated  over.  Collection  (capital  ‘C’),  which  is  actually  the  java.util.Collection  interface  from  which  Set  and  List  extend.  Collections (capital ‘C’ and ends with ‘s’),  which is actually the java.util.Collections class that holds a  pile of static utility methods for use with collections.    
    12. java.util.List  A List is a ordered collection of objects  Implemented by ArrayList, Vector & LinkedList  Users have control on where in List, new  element in the list should be added  List can contain duplicates element    
    13. ArrayList   It is an growable array. It gives you fast  iteration and fast random access.  Adding element require O(n) time.  ArrayList is not synchronized   Choose it when you need fast iteration but  aren’t as likely to be doing a lot of insertion and  deletion.    
    14.    
    15. Vector  Vector is a holdover from the earliest days of  Java  A Vector is basically the same as an ArrayList,  but Vector() methods are synchronized for  thread safety.    
    16. LinkedList  Doubly Linked List implementation of List  Interface  provide special method to get , remove and  insert element at the beginning and at the  end  of List  Very efficient  for sequential access  and  insertion of element in the middle of the List     
    17.    
    18. java.util.Set  A Set is a collection that does not contain any  duplicate element.  Element that are put in  a set must override  equals() method to establish uniqueness    
    19. HashSet  It is an unsorted, unordered Set  A Set BackedUp by HashMap  can contain null  basic operation take constant time  Iteration order may not always be same  Choose set where lookup time has to be  optimized   Operations are not synchronized  
    20. HashMap    
    21. LinkedHashSet  It is an ordered version of HashSet  It maintains a doubly­linked List across all  elements.  can contain null  Use it instead of HashSet when you care about  the iteration order    
    22.    
    23. TreeSet  It is guaranteed to be in ascending order, sorted  by the natural order of the element or by the  comparator provided.  It uses a Red­Black tree structure  can't contain null  User defined class must implement comparable  interface   It is not synchronized  
    24. Map interface  Map maps keys to values  Used to lookup object based on key  Doesn't extend Collection, but provides similar  methods  – put(), get(), remove() operate with single key­value pairs  – containsKey(), containsValue() check for existense  – Collection views: keySet(), values(), entrySet()    
    25. java.util.HashMap  Implementation is based on Hashtable  Ideal for fast lookup  Provide constant time performance for inserting  & locating pair  Allows one null key in a collection and multiple  null values in a collection    
    26. java.util.Hashtable  Hashtable is the synchronized counterpart to  HashMap.  HashMap lets you have null values as well as  one null key, a Hashtable doesn’t let you have  anything that’s null.    
    27. java.util.LinkedHashMap  It maintains insertion order  it will be somewhat slower than HashMap for  adding and removing elements  you can expect faster iteration with a  LinkedHashMap    
    28. java.util.TreeMap  Implemented based on Red­Black tree  The keys appear sorted  Basic operation take log(n) time  Methods are not synchronized    

    + ankitgarg_erankitgarg_er, 5 months ago

    custom

    1000 views, 4 favs, 0 embeds more stats

    A brief discription on Java Collection framework

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1000
      • 1000 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 4
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories