# Ternary Operator

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

A single line if/else statement.

## What is the **Ternary Operator**?

A single line if/else statement.

```java
double chocolate = 2.50;
double donuts = 3.99;

double maxPrice = (chocolate > donuts) ? chocolate : donuts;
```

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)
- [Ternary Operator in JavaScript](https://www.ask-codey.com/glossary/ternary-operator-javascript-2)

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