# Ternary Operator

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/subjects/java/apprentice)

Updated: October 15, 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
