In AP Computer Science A, == is a relational operator that compares two values and evaluates to a boolean. With primitive types (int, double, boolean) it compares the actual values; with reference types (like String objects) it compares whether two references point to the same object.
The == operator asks one question. Are these two things equal? It always evaluates to a boolean, true or false, which is why it shows up constantly inside if statements and while loop conditions. Per EK 2.2.A.1, you can pair it with != (not equal) to test the opposite.
Here's the part the AP exam loves. What "equal" means depends on the type. For primitives like int, double, and boolean, == compares the actual stored values, so 5 == 5 is true. For reference types like String or any object, == compares the references, meaning it checks whether both variables point to the exact same object in memory. Two different String objects can hold identical text and still make == return false. That's why Java objects get compared with .equals() instead, and why mixing those two up is one of the most common point-losers in the course.
The == operator lives in Topic 2.2 (Boolean Expressions) in Unit 2: Selection and Iteration, directly supporting learning objective 2.2.A, which asks you to build boolean expressions with relational operators and determine what they evaluate to. It's also foundational glue for the rest of the course. Every if statement (Topic 2.3 onward), every loop condition, and every search algorithm you write in later units depends on getting equality checks right. If you compare two Strings with == when you meant .equals(), your selection logic silently breaks, and on the FRQs that costs points.
Keep studying AP® Computer Science A Unit 2
Relational operators (Unit 2)
== is one member of the relational operator family alongside !=, <, >, <=, and >= (EK 2.2.A.2). All of them evaluate to a boolean, so any of them can sit inside an if condition or get combined with && and ||.
Object reference (Unit 2)
Understanding == on objects requires understanding references. A reference variable stores a pointer to an object, not the object itself, so == on two object variables asks "same address?" not "same contents?" That one mental model explains every == vs .equals() question you'll see.
Null comparison (Unit 2)
The one place == is the correct tool for objects is checking for null. Writing obj == null is safe, while calling obj.equals(...) on a null reference throws a NullPointerException. This pattern shows up in defensive code on FRQs.
Loop conditions and searching (Unit 2 and beyond)
Equality checks drive while loops and linear search. When you search an array of Strings later in the course, the difference between arr[i] == target and arr[i].equals(target) is the difference between code that works and code that only looks like it works.
Multiple-choice questions test == in two main ways. First, trace questions where you evaluate a boolean expression and pick what prints or which branch runs. Second, trap questions where two Strings or objects with identical contents are compared with == and the answer hinges on knowing it compares references, not contents. No released FRQ centers on == by itself, but nearly every FRQ requires it. Methods that count matches, search for a value, or validate input all need correct equality checks, and graders expect .equals() for object contents and == for primitives and null checks. Also watch for the classic typo distractor where a single = (assignment) appears where == (comparison) belongs.
== on objects asks "do these two variables point to the same object in memory?" while .equals() asks "do these two objects have the same contents?" For Strings, s1.equals(s2) returns true when the text matches even if they're different objects, but s1 == s2 can return false for identical text. Rule of thumb for the exam: == for primitives and null checks, .equals() for object contents.
The == operator always evaluates to a boolean, true or false, which is what makes it usable inside if statements and loop conditions.
With primitive types like int and double, == compares the actual values, so 7 == 7 is true.
With reference types like String, == compares references, meaning it only returns true if both variables point to the exact same object.
Use .equals() to compare the contents of objects and == to compare primitives or to check whether a reference is null.
A single = is assignment, not comparison, and Java will not let you accidentally use it as a condition the way some languages do (except with booleans, which is a sneaky MCQ trap).
== pairs with != as the two equality-based relational operators defined in EK 2.2.A.1.
It's a relational operator from Topic 2.2 that compares two values for equality and evaluates to a boolean. With primitives it compares values; with reference types it compares object references (EK 2.2.A.1).
It compiles, but it usually doesn't do what you want. == on Strings checks whether two variables reference the same object, so two Strings with identical text can still make == return false. Use .equals() to compare String contents.
A single = assigns a value to a variable, while == compares two values and returns a boolean. Writing if (x = 5) is a compile error for an int, but if (flag = true) compiles and assigns instead of comparing, which makes it a favorite MCQ distractor.
Use == for primitive types (int, double, boolean, char) and for null checks like obj == null. Use .equals() whenever you care about whether two objects, especially Strings, have the same contents.
Yes. It's spelled out in EK 2.2.A.1 under learning objective 2.2.A, and it appears throughout the exam in boolean expressions, if statements, loop conditions, and code-tracing multiple-choice questions.
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.