# Ternary Operator

say it: **“TER-nuh-ree OP-uh-ray-ter”** **/ˈtɜːrnəri ˈɑpəˌreɪtɚ/**

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.

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

Level: Apprentice · [More Java terms at this level](https://www.ask-codey.com/glossary?category=java&level=2)

Updated: November 17, 2026

## In other subjects

- [Ternary Operator in C#](https://www.ask-codey.com/glossary/ternary-operator-c-style)
- [Ternary Operator in Java](https://www.ask-codey.com/glossary/ternary-operator-java)
- [Ternary Operator in JavaScript](https://www.ask-codey.com/glossary/ternary-operator-javascript-2)

Source: https://www.ask-codey.com/glossary/ternary-operator
