Get all updates of Java4s

Difference between Java Set, List and Map Collections?

Let us see the main differences between Set,List,Map java collections..

Set (Interface)

  • Set is an un-ordered collection which doesn’t allows duplicate (no-duplicate) elements
  • We can iterate the values by calling iterator() method

Set s = new HashSet();
Iterator iter = s.iterator();

List (Interface)

  • List is an ordered collection which allows duplicate elements
  • We can iterate the values by calling iterator() method

List li = new ArrayList();
Iterator iter = li.iterator();

Map (Interface)

  • In Map we used to store the data in key and value pairs, we may have duplicate values but no duplicate keys
  • In Map we don’t have iterator() method, but we can get the keys by calling the method keySet()


You Might Also Like

  ::. About the Author .::

- Full Stack Java/J2EE & UI Web Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


13 Responses to “Difference between Java Set, List and Map Collections?”
  1. hussain says:

    Hi sir, could u please explain about jUnit.

  2. kiran says:

    Please make a small correction while explaining about List you misspelled ‘Set’ instead List.

    – Modified

  3. praveen says:

    Please tell the answers in real time scenarios.

  4. vinayak says:

    sir pls explain more details in collection with example

  5. Ajit says:

    Hi Sir!, wait,notify,notifyall methods are related to Thread class then why they are found in Object class,Please explain…..I am waiting …

    • Ganesh says:

      wait,notify,notifyall methods are called on object(user defined like studentObject).so theses methods are defined in Object class

  6. suresh says:

    please explain about arraylist and hashcode & map

  7. Selva says:

    Nice content for collection concept.

  8. prasad says:

    Hi ,

    Could you please explain about JUnit with example ?

    Thanks In Advance,

  9. bhavana says:

    sir pls explain more details about collection with example

  10. Shubham Singh Parmar says:

    IF HashSet internally implements HashMap, then what is the purpose of HashSet as a separate Class when ultimately every task is done by HashMap itself? Can anyone please sort this confusion for me????

  11. Manish says:

    Sir, Please explain Comparator and Comparable Interfaces.

  12. Ganesh says:

    1. It preserves the insertion order.
    2. retrieving elements is very vast.
    3. It is internal index based mechanism(It internally follows the arrays)
    4. insertion,deletion of elements in the ArrayList is slow. because of it follows the index base. if you remove one element in the list. it will change the index.


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Spring-Boot-tutorials Hibernate tutorials Spring tutorials Struts tutorials Servlets tutorials Ajax tutorials Log4j tutorials jQuery tutorials Json tutorials Core Java tutorials Web Services tutorials AngularJs tutorials
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.