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

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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 Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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 Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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...
 

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