This is an interesting operator in Java.
class TernaryOperator{
public static void main(String[] args){
int value1 = 1;
int value2 = 2;
int result;
boolean someCondition = true;
result = someCondition ? value1 : value2;
System.out.println("First Result " +result);
someCondition = false;
result = someCondition ? value1 : value2;
System.out.println("Second Result " +result);
}
}
Output:
First Result 1
Second Result 2
The code is self explanatory