> For the complete documentation index, see [llms.txt](https://kdoore.gitbook.io/cs1335/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kdoore.gitbook.io/cs1335/java/java_syntax/ternary_operator.md).

# Ternary Operator

The Ternary Operator: ? , is a conditional operator that provides a shortcut assignment operator based on whether a condition evaluates to true or false.

The same logic can be represented using if - else logic, but Ternary operator provides a more concise format when using conditional logic to determine the value assigned to a variable.

Example logic: Goal - determine value to be assigned to index

* if someTest is true
* then set index = 5
* otherwise, index = 10

```
int index=0; // initialze value

if( someTest == true){
   index = 5;
}else{
   index = 10;
}
/////  Same Logic using Ternary Operator:

index = (someTest == true) ? 5 : 10;
```
