Difference between List and Set and Map?

List are ordered, and you can have duplicates.

i.e. you add A B C A D, and if you iterate through, you'll get A B C A D right back.

Sets are unordered, and you can't have duplicates.

So if you add A B C A D, you could get back A B C D or A C B D etc.

Maps are key-value pairs, rather than just a collection of items. You can have duplicate values, but not duplicate keys.

So you add in things like:


To iterate through them you'll have to say map.keyset.iterator, then use the keys to lookup the values. There's also something like map.valueset or .entryset if you want to go through the values without knowing the keys.