Computer Science
Forgetting That List Indexes Start at Zero
Treating the first item in a list as index 1 instead of index 0.
Quick check
Why students make it
People count starting at one in everyday life, so the first item feels like number one.
The rule done right
In most languages the first element is at index 0 and the last is at index length minus 1. A list of 5 items has indexes 0 through 4.
Related resources
- Programming Fundamentals Cheat Sheet
- AP Computer Science A Java Reference Cheat Sheet
- Data Structures Overview Cheat Sheet
- Sorting Algorithms Comparison Cheat Sheet
- Algorithms & Big-O Notation Cheat Sheet
- CS, Arrays and Lists Worksheet
- CS, Loops and Control Flow Worksheet
- CS, Sorting Algorithms, Bubble, Selection, and Insertion Worksheet
- CS, Java, Classes, Methods, and Public Static Void Main Worksheet
- Java Array & ArrayList Explorer Tool
- Data Structure Visualizer Tool
- Sorting Algorithm Visualizer Tool
- Debugging & Unit Testing Explorer Tool
- Arrays & ArrayList Lab Lab
- Selection & Iteration Code Tracing Lab Lab
- Debugging & Unit Testing Lab Lab
- Searching & Sorting Performance Lab Lab
- Loops, Debugging & Animation Lab Lab