some times, for simple if else conditions, we can write one line if-else statements to add more readability for your apex code.
Single line if else:
// multi line if else
string countryCode;
String country= 'Australia';
if(country =='India'){
countryCode = 'IN';
}else{
countryCode = 'OTHER';
}
// now in single line if-else
countryCode = (country =='India') ? 'IN': 'OTHER';
Complex single line if else
// multi line if else
string countryCode;
String country= 'Australia';
if(country =='India'){
countryCode = 'IN';
}else if(country =='Australia'){
countryCode = 'AUS';
}else{
countryCode = 'OTHER';
}
// now in single line if-else
countryCode = (country =='India') ? 'IN': (country =='Australia')? 'AUS' : 'OTHER';