• 4 hours
  • Easy

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 6/15/21

Discover the list data type

List container

The list data type is similar to the array we just looked at. The list stores its objects in buckets but does not impose a fixed number of buckets. Once created, it is empty and can grow as you add additional objects to it. Consider the huge egg provider, Acme Egg Company. They have thousands of chickens laying eggs.

Chicken Laying Eggs
Chicken & eggs

Acme cannot determine in advance how many eggs will be produced by their chickens. This makes the unbounded list container ideal for this scenario.  Not surprisingly, the List itself is an object that stores your objects. The list contains an arrangement of objects you have added.  As you saw in the video, there are two types:

  • ordered, meaning that which spot each element is placed on the list matters.

  • unordered, meaning that you group these items together, but it doesn't matter which one comes first, last, or fifteenth.  

You can access a bucket in any particular position in the list. You can also insert into or remove an object at any particular position. The size of your list can grow/shrink in real time as objects are added and removed. It may also contain duplicates if you wish.

Try it out for yourself

  1. Do you think Acme should use ordered or unordered lists for its eggs? 

  2. Brainstorm a few real-world groups of objects that would be useful to put in a list.  Decide whether ordered or unordered lists would be better for each one of your groups of objects.  

Summary

  • List is an ordered container of objects.

  • List size is dynamic and can become bigger or smaller according to your needs. 

Ever considered an OpenClassrooms diploma?
  • Up to 100% of your training program funded
  • Flexible start date
  • Career-focused projects
  • Individual mentoring
Find the training program and funding option that suits you best
Example of certificate of achievement
Example of certificate of achievement