AP CSA Unit 4.6: File Processing and ArrayList Concepts Practice
Share
Unit 4, Section 4.6
Day 6 Practice • January 12, 2026
🎯 Focus: File Processing Concepts
Practice Question
A program reads student names from a text file and stores them in an ArrayList. The file contains one name per line. After reading all names from the file, which of the following statements is TRUE?
What This Tests: Section 4.6 covers using text files with data structures. ArrayList grows dynamically as you add elements—its size matches the number of items added, which equals the number of lines read from the file.
Key Concept: Dynamic ArrayList
ArrayList<String> names = new ArrayList<String>();
// Reading from file (conceptual)
while (file.hasNextLine()) {
String name = file.nextLine();
names.add(name); // ArrayList grows with each add
}
// names.size() == number of lines in file
ArrayList vs Array
Key Differences
Array: Fixed size, must declare size upfront
String[] arr = new String[100];
ArrayList: Dynamic size, grows as needed
ArrayList<String> list = new ArrayList<String>();
Common Mistakes
Mistake: Answer A (always 100)
ArrayLists don't have a fixed size. They grow dynamically. Only arrays have fixed sizes.
Mistake: Answer C (declare fixed size)
ArrayLists do NOT require a fixed size. That's their main advantage over arrays!
Mistake: Answer D (sorted)
Reading from a file preserves the original order. Data is NOT automatically sorted.
File Processing Pattern
// Common pattern for reading file into ArrayList:
// 1. Create empty ArrayList
// 2. Loop while file has more data
// 3. Read one item
// 4. Add to ArrayList
// 5. Result: list.size() == items in file
Difficulty: Medium • Time: 2 minutes • AP Skill: 3.D - Data structures
Ready to Level Up Your AP CSA Skills?
Get personalized help or access our complete question bank
Premium Question Bank - Coming Soon Schedule 1-on-1 Tutoring