Ternary Operator

The ?: operator, which chooses one of two values from a condition.

What does Ternary Operator do in Java?

Ternary Operator — The ?: operator, which chooses one of two values from a condition.

class Inventory {
    String stockLabel(int stock) {
        return stock > 0 ? "Available" : "Sold out";
    }
}

Level: Apprentice · More Java terms at this level

Updated

In other subjects