SlideShare a Scribd company logo
1 of 28
Collection Framework

        Ankit Kumar Garg




                
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.
                                 

        Java 1.2 introduced the Collections Framework
    
        Another example of a collections framework is 
        the STL(Standard Template Library) in C++.




                               
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.


                                     

        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.




                                       
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



                               
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.
                              
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.
Java Collection Classes




                
Map classes




          
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.
                                      
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



                                 
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.
                                 
     
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.




                                
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 

                                 
     
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




                                
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
                            
HashMap




        
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


                                 
     
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    
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()

                                        
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


                                 
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.




                               
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




                                
java.util.TreeMap

    
        Implemented based on Red­Black tree
    
        The keys appear sorted
    
        Basic operation take log(n) time
    
        Methods are not synchronized




                               

More Related Content

What's hot (20)

Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Java collections
Java collectionsJava collections
Java collections
 
String in java
String in javaString in java
String in java
 
JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
Java awt
Java awtJava awt
Java awt
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
07 java collection
07 java collection07 java collection
07 java collection
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 

Similar to Introduction to Java Collections Framework

Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Sagar Verma
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questionsArun Vasanth
 
Java collections
Java collectionsJava collections
Java collectionsAmar Kutwal
 
Java Hands-On Workshop
Java Hands-On WorkshopJava Hands-On Workshop
Java Hands-On WorkshopArpit Poladia
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVASAGARDAVE29
 
Collections Java e Google Collections
Collections Java e Google CollectionsCollections Java e Google Collections
Collections Java e Google CollectionsAndré Faria Gomes
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxeyemitra1
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structuresagorolabs
 
Java collections
Java collectionsJava collections
Java collectionspadmad2291
 
Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxrangariprajwal4554
 
Slide Dasar Materi Java Collection Framework
Slide Dasar Materi Java Collection FrameworkSlide Dasar Materi Java Collection Framework
Slide Dasar Materi Java Collection FrameworkBayu Rimba
 

Similar to Introduction to Java Collections Framework (20)

Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questions
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
Java collections
Java collectionsJava collections
Java collections
 
Java collections
Java collectionsJava collections
Java collections
 
Java util
Java utilJava util
Java util
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
 
Java Hands-On Workshop
Java Hands-On WorkshopJava Hands-On Workshop
Java Hands-On Workshop
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
Java for newcomers
Java for newcomersJava for newcomers
Java for newcomers
 
Collections Java e Google Collections
Collections Java e Google CollectionsCollections Java e Google Collections
Collections Java e Google Collections
 
Collections
CollectionsCollections
Collections
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptx
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Java collections
Java collectionsJava collections
Java collections
 
Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptx
 
Slide Dasar Materi Java Collection Framework
Slide Dasar Materi Java Collection FrameworkSlide Dasar Materi Java Collection Framework
Slide Dasar Materi Java Collection Framework
 
Collections Training
Collections TrainingCollections Training
Collections Training
 

Recently uploaded

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Recently uploaded (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Introduction to Java Collections Framework

  • 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.
  • 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  
  • 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