Note: These concepts aren't tested on the AP exam, but they're useful tools that can make your code cleaner and more efficient.
A ternary operator is like a compact if-else statement that fits on one line. Think of it as asking a yes/no question and getting one of two answers instantly. These are useful when trying to write neat code, allowing you to shrink an entire if-else statement into one line of code.
int age = 19;
String status = (age >= 18) ? "Adult": "Minor";
System.out.println(status);Output
Adult