Inline Lists
The Spring Expression Language (SpEL ) is a simple and powerful expression language
which helps to query and manipulate objects at runtime.
The following example shows creating inline lists using SpEL.
package com.bethecoder.tutorials.spring3.tests.spel;
import java.util.List;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class InlineListTest {
/**
* @param args
*/
public static void main ( String [] args ) {
ExpressionParser parser = new SpelExpressionParser () ;
List numbers = parser.parseExpression ( "{1, 2, 3, 4, 5, 6}" ) .getValue ( List. class ) ;
System.out.println ( numbers ) ;
List strings = parser.parseExpression ( "{'one', 'two', 'three', 'four'}" ) .getValue ( List. class ) ;
System.out.println ( strings ) ;
List listOfLists = ( List ) parser.parseExpression ( "{{'a','b', 'c'},{'d','e', 'f'}}" ) .getValue () ;
System.out.println ( listOfLists ) ;
}
}
It gives the following output,
[1, 2, 3, 4, 5, 6]
[one, two, three, four]
[[a, b, c], [d, e, f]]