In AP Computer Science A, equality comparison tests whether two values are the same, using == (or !=) for primitive values and the .equals() method for objects. With primitives, == compares actual values; with reference types, == compares whether two variables point to the same object (EK 2.2.A.1).
Equality comparison is how Java answers a yes-or-no question, namely "are these two things the same?" The result is always a Boolean value, true or false, which is exactly what if statements and loops need to make decisions.
The catch, and the part the AP exam loves, is that how you check equality depends on what you're comparing. For primitive types like int, double, and boolean, the == operator compares the actual values, so 5 == 5 is true. For reference types like String or any object, == compares the references, meaning it asks "do these two variables point to the exact same object in memory?" Two different objects can hold identical data and still fail an == check. To compare what objects actually contain, you call .equals(). The != operator works the same way as == but flipped, and it has the same primitive-vs-reference behavior.
Equality comparison lives in Topic 2.2 (Boolean Expressions) in Unit 2: Selection and Iteration, and it directly supports learning objective 2.2.A: develop code to create Boolean expressions with relational operators and determine the result of these expressions. EK 2.2.A.1 spells out the rule the exam tests over and over, that == and != compare actual values for primitives but compare references for objects.
This matters way beyond Unit 2. Every if statement, while loop condition, and search algorithm you write for the rest of the course depends on getting equality right. The == vs .equals() distinction is one of the most reliable trap setups in multiple-choice questions, because code that looks correct can return false when two distinct String objects hold the same characters.
Keep studying AP® Computer Science A Unit 2
== (equality operator) (Unit 2)
The == operator is the tool that performs equality comparison on primitives. The concept is the question ("are these equal?") and == is one specific way Java asks it. Knowing when == gives the right answer and when it doesn't is the whole game.
Relational operators (Unit 2)
Equality comparison is one slice of the relational operator family. EK 2.2.A.2 adds <, >, <=, and >= for numeric ordering, and EK 2.2.A.3 reminds you that all of these expressions evaluate to a Boolean. Same machinery, different question being asked.
Object reference (Units 1-2)
You can't fully understand equality comparison without understanding references. When two variables refer to the same object, they're aliases, so == returns true. When they refer to two separate but identical-looking objects, == returns false. This is the mental model behind EK 2.2.A.1.
null comparison (Unit 2)
null is the one case where == is the right choice for a reference type. Checking obj == null is safe, but calling obj.equals(...) on a null reference throws a NullPointerException. This combo shows up constantly in defensive code on FRQs.
Equality comparison shows up most often in multiple-choice questions that ask you to trace code and determine what a Boolean expression evaluates to. A typical stem hands you a method packed with comparisons and asks what it accomplishes. For example, one practice question gives you boolean condition = (x < y) == false; followed by return condition && (x != y); and asks you to untangle it. Notice that == false is itself an equality comparison applied to a Boolean, so (x < y) == false is just a clunky way of writing !(x < y), or x >= y. Combined with x != y, the method returns true exactly when x > y.
No released FRQ uses the phrase "equality comparison" verbatim, but nearly every FRQ requires it in practice. You'll write conditions like if (grid[r][c] == target) for primitives or if (name.equals(other.getName())) for Strings. Using == on Strings in an FRQ is a classic way to lose a point, so default to .equals() for objects unless you're checking for null.
Both check equality, but they ask different questions. == on reference types asks "are these the same object?" while .equals() asks "do these objects have the same contents?" Two Strings built separately with the same characters are .equals() but may not be ==. Rule of thumb for the exam: == for primitives and null checks, .equals() for everything else.
Equality comparison uses == and != to test whether two values are the same, and the result is always a Boolean (EK 2.2.A.1, EK 2.2.A.3).
With primitive types like int and double, == compares the actual values directly.
With reference types like String, == compares references, so it only returns true when both variables point to the exact same object.
Use .equals() to compare the contents of objects, because two separate objects can hold identical data and still fail an == check.
Writing (someBoolean == false) is the same as !someBoolean, and the exam likes to dress up simple conditions this way to test whether you can simplify them.
The one time == is correct for objects is null checking, since calling .equals() on a null reference crashes with a NullPointerException.
It's testing whether two values are the same, using == or != for primitives and the .equals() method for objects. It's part of Topic 2.2 (Boolean Expressions) in Unit 2, and the result is always a Boolean value.
Technically yes, but it usually gives the wrong answer. Since String is a reference type, == checks whether two variables point to the same object, not whether they contain the same characters. Use .equals() to compare String contents, which is what AP FRQ scoring expects.
For objects, == compares references (same object in memory?) while .equals() compares contents (same data?). For primitives like int and double, == compares actual values and .equals() doesn't apply, since primitives aren't objects.
Yes, for primitives those two expressions always evaluate to the same Boolean. For reference types, both compare references, so they're still equivalent to each other but neither checks object contents.
Because they're two different objects. If two String variables were created separately, == compares their references and returns false even though the characters match. EK 2.2.A.1 makes this primitive-vs-reference distinction explicit, and it's a favorite multiple-choice trap.
Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.
Review units, study guides, and course resources.
Check this vocabulary in multiple-choice context.
Apply key concepts in written AP responses.
Estimate the exam score you are working toward.
Review the highest-yield facts before practice.
Put the full course together before test day.