When to use a Map instead of a List in Java?

Java map: An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.

Java list: An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.

The difference is that they are different. Map is a mapping of key/values, a list of a list of items.

Leave a Comment