Creating Lists and Indexing
Build lists and access items by position.
Creating Lists and Indexing is a free Dart Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What a List Is
A List is an ordered bucket of values you can hold in one variable. Think of it as a numbered row of boxes, each storing one item. 📦
Your First List
Write a list with square brackets and commas. The literal below holds three fruit names in the exact order you typed them.
var fruits = ['apple', 'banana', 'cherry'];Order Is Kept
Lists remember order. The first item you add stays first, the last stays last, and printing the list shows them just as you wrote them.
print(fruits); // [apple, banana, cherry]Index Starts at Zero
Each item has a position called its index. Dart counts from 0, so the very first item lives at index 0, not 1.
Reading by Index
Grab one item with square brackets and its index. Here fruits[1] reaches past the first item to give you 'banana'.
print(fruits[1]); // bananaThe Last Index
The last index is always one less than the count. A three-item list ends at index 2, so its last item is fruits[2].
print(fruits[2]); // cherryHow Many Items
Ask a list its size with length. It returns the total count, which is handy for loops and bounds checks.
print(fruits.length); // 3Out of Range Errors
Reaching an index that does not exist throws a RangeError. With three items, index 3 is one step too far and crashes.
print(fruits[3]); // RangeError!Typed Lists
You can declare the item type up front. A List of int only accepts whole numbers, so Dart catches mistakes before you run.
List<int> scores = [10, 20, 30];An Empty List
Start with nothing and fill later using empty brackets. Always give an empty list a type so Dart knows what belongs inside it.
List<String> names = [];Handy Shortcuts
Lists offer friendly getters too. Use first and last to peek at the ends without counting indexes yourself.
print(fruits.first); // appleQuick Check
You have a list of 5 items. Which index points to the last one?
Recap
Nice work! You built lists with brackets, read items by index from 0, checked length, and dodged range errors. Lists are now in your toolkit. 🎉
Frequently asked questions
Is the “Creating Lists and Indexing” lesson free?
Yes — the full text of “Creating Lists and Indexing” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “Creating Lists and Indexing”?
Build lists and access items by position. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Creating Lists and Indexing” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Creating Lists and Indexing
- Adding, Removing, and Updating Items
- Searching and Sorting Lists
- Transforming With map, where, and toList