Which collection type is ordered and allows duplicates?

Prepare for the Object-Oriented Programming Test with flashcards and multiple choice questions. Each question comes with hints and explanations to enhance understanding. Master OOP concepts and succeed in your exam!

Multiple Choice

Which collection type is ordered and allows duplicates?

Explanation:
A list is the collection that is ordered and allows duplicates. The order means elements have a defined sequence, so you can access them by position and the sequence is preserved as you add them. Duplicate values are allowed, so you can have repeated elements in the same collection, like [1, 2, 2, 3]. Sets enforce uniqueness, so duplicates aren’t allowed, and maps store key-value pairs where keys are unique and iteration focuses on those pairs rather than a simple ordered list of elements. An iterable is just something you can traverse, but it doesn’t specify a particular storage behavior regarding order or duplicates. So the combination of preserving order and permitting duplicates is uniquely provided by a list.

A list is the collection that is ordered and allows duplicates. The order means elements have a defined sequence, so you can access them by position and the sequence is preserved as you add them. Duplicate values are allowed, so you can have repeated elements in the same collection, like [1, 2, 2, 3]. Sets enforce uniqueness, so duplicates aren’t allowed, and maps store key-value pairs where keys are unique and iteration focuses on those pairs rather than a simple ordered list of elements. An iterable is just something you can traverse, but it doesn’t specify a particular storage behavior regarding order or duplicates. So the combination of preserving order and permitting duplicates is uniquely provided by a list.