Return to site

What’s the difference between a Set and a List in Java?

· java,interview,video

🚀 Java Interview Questions – Episode 11

💡 What’s the difference between a Set and a List in Java?

Both are part of the Collection framework, but they serve different purposes:

📋 List

➡️ Ordered collection

➡️ Allows duplicate elements

➡️ Elements can be accessed by index

🔸 Implementations: ArrayList, LinkedList

🧮 Set

➡️ Unordered (in general – unless using LinkedHashSet or TreeSet)

➡️ Does NOT allow duplicates

➡️ No index-based access

🔸 Implementations: HashSet, LinkedHashSet, TreeSet

🧠 When to use what?

Use List when you care about order or need duplicates

Use Set when you need uniqueness and don't care about duplicates