How to use the Exposition Language 3.0 API in the Java Library to implement programming functions

Using the Expression Language (EL) 3.0 API in the Java Library can achieve strong programming functions in the Java application.EL is part of the JavaseerVer Pages (JSP) specification, which provides a simple way to process expressions in Web applications.EL 3.0 API is part of the Java EE 7, which introduces some new features, such as the support of the collection and Lambda expression. In this article, we will explore some of the main functions of the EL 3.0 API and provide some Java code examples to illustrate how to use them. 1. Basic usage of EL expression EL allows assessment expressions during runtime.It can be used to access the attributes, methods and set elements of the object.The following is a simple example, which demonstrates how to use EL expressions to calculate the two integers: import javax.el.ExpressionFactory; import javax.el.ELContext; import javax.el.ValueExpression; import javax.el.ELProcessor; public class Example { public static void main(String[] args) { // Create an EL context ELProcessor elp = new ELProcessor(); ELContext context = elp.getELManager().getELContext(); // Define two integers Integer num1 = 10; Integer num2 = 20; // Bind the variables to the context context.getVariableMapper().setVariable("a", elp.getELManager().getExpressionFactory().createValueExpression(num1, Integer.class)); context.getVariableMapper().setVariable("b", elp.getELManager().getExpressionFactory().createValueExpression(num2, Integer.class)); // Calculate A + B, and print the results ValueExpression ve = elp.getELManager().getExpressionFactory().createValueExpression(context, "${a + b}", Integer.class); System.out.println (ve.getvalue (context)); // Output 30 30 } } 2. Collection traversal EL 3.0 API introduces new features that are traversed.It can use LAMBDA expressions to filter, mappore and sort the elements in the set.The following is an example of how to use EL traversal collection: import java.util.Arrays; import javax.el.ExpressionFactory; import javax.el.ELContext; import javax.el.ValueExpression; import javax.el.ELProcessor; public class Example { public static void main(String[] args) { // Create an EL context ELProcessor elp = new ELProcessor(); ELContext context = elp.getELManager().getELContext(); // Define a string array String[] names = {"Alice", "Bob", "Charlie", "David"}; // Bind the variables to the context context.getVariableMapper().setVariable("names", elp.getELManager().getExpressionFactory().createValueExpression(names, String[].class)); // Print out the name starting from the capital letter ValueExpression ve = elp.getELManager().getExpressionFactory().createValueExpression(context, "${names.stream().filter(name -> Character.isUpperCase(name.charAt(0))).toList()}", String[].class); System.out.println(Arrays.toString((String[]) ve.getValue(context))); // 输出[Alice, Charlie, David] } } The above examples show some basic functions of how to use EL 3.0 API.Through EL expression, we can flexibly access the attributes and methods of the object.The functions of the collections make us more conveniently operate and handle elements in the set.In actual applications, EL 3.0 API can be used with other Java technology (such as Servlet, JSF, etc.) to achieve more powerful functions.