CodesJava

Easy learning with example program codes

Spring spel ternary operator example


Ternary operator syntax:

condition ? true : false

Spring SpEL Ternary Operator Example:

TernaryOperatorTest.java

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
 
/**
 * Spring SPEL Ternary Operator test example.
 * @author codesjava
 */
public class TernaryOperatorTest {
	public static void main(String args[]){
		//Create a parser with default settings.
		ExpressionParser parser = new SpelExpressionParser(); 
 
		//Ternary operator expressions. 
		System.out.println(parser.parseExpression(
				"10 < 20? true: false").getValue());
	}
}

Output:

true

 
Download this example.
 

Please follow and like us:

Spring Tutorial



Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki