Difference between Java Set, List and Map Collections?

Core Java » On Oct 21, 2012 By Sivateja

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

 

Java4s_Author
Java/J2EE Developer & Web Designer, founder of Java4s.com. Sign-up for the email newsletter for your daily dose of Java tutorials.
Email: sivateja@java4s.com

Comments

10 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 …

  6. suresh says:

    Sir,
    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,
    Prasad

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

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
       
© 2010 - 2016
Java4s - Get It Yourself.
The content & design is copyrighted to Sivateja Kandula, it may not be reproduced on other websites.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs

Most Recent Tutorials
Hibernate Recent Posts
Spring Recent Posts
Struts Recent Posts
Recomandded Links
Current & UpComing Tutorials
Upcoming
  Web Services [ SOAP ], JSP
Facebook_Java4s  Twitter_Java4s  GooglePlus_Java4s  Youtube_Java4s 
Contact | About Us | Privacy Policy | Advertise With Us

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