Dove's LibraryDove's Library

4.2 - Introduction to Using Data Sets

A data set is just a collection of specific pieces of information. You can manipulate and analyze data sets to solve a problem or answer a question, usually by accessing values one at a time and processing them toward whatever outcome you’re after.
Data is often represented visually with a chart or table, which can help you plan out the algorithm you’ll use to work with it.
Name
Test Score
Ana
88
Ben
72
Chloe
95
Dev
81
Eli
64
A table like this makes it easier to plan. Before writing any code, you can describe the algorithm in plain words. To find the class average:
  1. Start a total at 0.
  1. Go through the scores one at a time, adding each score to the total.
  1. After the last score, divide the total by the number of scores.
Here the total is 88 + 72 + 95 + 81 + 64 = 400, so the average is 400 / 5 = 80.0. The same one-at-a-time idea answers other questions too. To find the highest score, keep track of the biggest score you’ve seen so far (Chloe’s 95). To count how many students scored 80 or above, add 1 to a counter each time a score passes the check (3 students).
In Java, a data set like this is usually stored in an array or an ArrayList (4.3 and 4.8), and a loop does the one-at-a-time part:
String[] names = {"Ana", "Ben", "Chloe", "Dev", "Eli"}; int[] scores = {88, 72, 95, 81, 64}; int total = 0; int best = 0; // index of the highest score so far for (int i = 0; i < scores.length; i++) { total += scores[i]; if (scores[i] > scores[best]) { best = i; } } double average = (double) total / scores.length; System.out.println(average); // 80.0 System.out.println(names[best]); // Chloe
Data sets show up all over everyday life: a playlist is a list of songs, a weather app stores a temperature for each day, and a gradebook stores a score for each assignment. The same plan works for all of them: access the values one at a time, then process each one toward the answer you want.

AP® is a registered trademark of the College Board, which is not affiliated with Dove's Library and was not involved in the production of, and does not endorse, this website.

Providing free, high-quality AP notes to help students succeed, earn college credit, and reach their educational goals, ensuring everyone has access to the resources they need.

© 2026 Standard Learning Group, Inc., which operates Dove's Library. All rights reserved.