Boolean array in AP Computer Science A

A boolean array is a 1D array whose elements are the primitive type boolean. Per EK 4.3.A.3, when you create one with the keyword new (like new boolean[10]), every element is automatically initialized to false, and the array's length is fixed at creation.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is boolean array?

A boolean array is exactly what it sounds like, an array where every element holds a true or false value. You can create one with new boolean[n] or with an initializer list like {true, false, true}. Like every Java array (EK 4.3.A.1), all elements share the same type, and the length is locked in at creation and accessed with the length attribute (EK 4.3.A.2).

The detail the AP exam loves is in EK 4.3.A.3. When you write new boolean[10], Java doesn't leave the slots empty. It fills all ten elements with the default value false. That makes boolean arrays perfect for tracking yes/no "flags," like which seats are taken or which numbers have been seen. You start with everything false and flip elements to true as your program runs. No loop needed to initialize them to false; Java does it for you.

Why boolean array matters in AP® Computer Science A

Boolean arrays live in Topic 4.3 (Array Creation and Access) in Unit 4: Data Collections, supporting LO 4.3.A, which asks you to develop code that represents collections of related data with 1D arrays. They matter because they're the cleanest test of whether you actually know default values. The default for int is 0, for double is 0.0, for boolean is false, and for any reference type is null. Boolean arrays also show up constantly as "flag" arrays in algorithm questions, where each index represents a thing and the value represents whether something is true about it. If you can write a loop that sets flags at certain indices, you've got the core skill Unit 4 is testing.

How boolean array connects across the course

Object reference (Unit 4)

A boolean array holds primitive values, but the array variable itself is an object reference. That means boolean[] flags is null until you actually create the array with new. It also means passing the array to a method passes the reference, so the method can change the original elements.

Out-of-bounds error (Unit 4)

Boolean arrays use zero-based indexing like every Java array, so new boolean[10] has valid indices 0 through 9. Touching flags[10] throws an ArrayIndexOutOfBoundsException at runtime. MCQs love pairing a flag-setting loop with an off-by-one bound to see if you catch it.

Default values for all array types (Unit 4)

Boolean arrays are one row in the EK 4.3.A.3 table you need cold. int defaults to 0, double to 0.0, boolean to false, references to null. A question that prints unset elements of a double[] and a boolean[] is really just quizzing this table, and the answer is something like "0.0 and false."

Is boolean array on the AP® Computer Science A exam?

Boolean arrays show up almost entirely in multiple-choice questions, and they test three things. First, default initialization. A method that's supposed to return n boolean values all set to false might need nothing more than new boolean[n], because false is the default; recognizing that the "do nothing" option works is the whole question. Second, pattern-filling loops. Classic stems give you boolean[] flags = new boolean[10] and ask which code makes even indices true and odd indices false, or sets just the first and last elements to true (flags[0] and flags[n - 1]). Third, printing unset elements, where the answer hinges on knowing the element prints as false, not 0 or null. On FRQs, boolean arrays appear as flag arrays inside larger array problems, so practice writing for loops that read and flip elements without going out of bounds.

Boolean array vs Boolean[] (wrapper class array)

A boolean[] holds primitive true/false values and defaults every element to false. A Boolean[] holds object references to Boolean wrapper objects, so its elements default to null like any reference type (EK 4.3.A.3). On the AP exam you'll work with the primitive version, but the default-value distinction is exactly the kind of detail an MCQ can hinge on.

Key things to remember about boolean array

  • A boolean array stores multiple true/false values of the primitive type boolean, all of the same type, as required by EK 4.3.A.1.

  • Creating a boolean array with new, like new boolean[10], automatically initializes every element to false, so you never need a loop just to set elements to false.

  • The length of a boolean array is fixed when it's created and is accessed with the length attribute, not a length() method.

  • Valid indices run from 0 to length - 1, so the last element of flags is flags[flags.length - 1], and anything past that throws an out-of-bounds exception.

  • Boolean arrays are the standard tool for flag patterns, where each index represents an item and true/false records whether something happened to it.

  • Know the full default-value table from EK 4.3.A.3: 0 for int, 0.0 for double, false for boolean, and null for reference types.

Frequently asked questions about boolean array

What is a boolean array in AP Computer Science A?

It's a one-dimensional array whose elements are the primitive type boolean, created with new boolean[n] or an initializer list like {true, false}. It falls under Topic 4.3 (Array Creation and Access) in Unit 4 and supports LO 4.3.A.

Do you have to initialize a boolean array to false in Java?

No. Per EK 4.3.A.3, when an array is created with the keyword new, every element gets the default value for its type, and for boolean that's false. So new boolean[n] already gives you n false values, and a loop that sets them to false is redundant (though not wrong).

What's the difference between boolean[] and Boolean[]?

boolean[] holds primitive values and defaults to false, while Boolean[] holds object references and defaults to null, since the default for any reference type is null. The AP exam works with the primitive boolean[] version.

What does an unset boolean array element print?

It prints false, not 0 and not null. Exam questions like to print one element from a fresh double[] and one from a fresh boolean[], and the correct output combines the defaults, for example "0.0 and false."

How do you set the first and last elements of a boolean array to true?

Use flags[0] = true and flags[flags.length - 1] = true. Everything else stays false automatically because of default initialization. Watch for answer choices that use flags[flags.length], which is out of bounds and throws an exception.