Menu
Coddy logo textTech

Creating a List

Part of the Fundamentals section of Coddy's Dart journey — lesson 49 of 94.

To create a list in Dart, you use square brackets and separate items with commas. Lists can store multiple values of the same type.

Create a list of strings:

List<String> fruits = ['Apple', 'Banana', 'Orange'];
print(fruits);

After executing the above code, the output will be:

[Apple, Banana, Orange]

Create a list of integers:

List<int> scores = [85, 92, 78, 96];
print(scores);

After executing the above code, the output will be:

[85, 92, 78, 96]
challenge icon

Challenge

Beginner

In this challenge, you'll create a simple shopping list using a Dart List. Lists are ordered collections that can store multiple values.

Complete the code below to create a shopping list with the following items: "Apples", "Bread", "Milk", and "Eggs".

After creating the list, the program will print it for you.

Expected output:

[Apples, Bread, Milk, Eggs]

Cheat sheet

To create a list in Dart, use square brackets and separate items with commas:

Create a list of strings:

List<String> fruits = ['Apple', 'Banana', 'Orange'];

Create a list of integers:

List<int> scores = [85, 92, 78, 96];

Use print() to display the list:

print(fruits); // Output: [Apple, Banana, Orange]

Try it yourself

void main() {
  // TODO: Create a list called 'shoppingList' containing the items:
  // "Apples", "Bread", "Milk", and "Eggs"
  
  
  // This will print your shopping list
  print(shoppingList);
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals