Arrays
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 single and multi dimentional arrays using SpEL.
package com.bethecoder.tutorials.spring3.tests.spel;
import java.util.Arrays;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class ArrayTest {
/**
* @param args
*/
public static void main ( String [] args ) {
ExpressionParser parser = new SpelExpressionParser () ;
int [] nums = ( int []) parser.parseExpression ( "new int [6]" ) .getValue () ;
System.out.println ( Arrays.toString ( nums )) ;
nums = ( int []) parser.parseExpression ( "new int [] {1, 2, 3, 4, 5, 6}" ) .getValue () ;
System.out.println ( Arrays.toString ( nums )) ;
int [][] nums2 = ( int [][]) parser.parseExpression ( "new int [6][4]" ) .getValue () ;
System.out.println ( nums2 ) ;
}
}
It gives the following output,
[0, 0, 0, 0, 0, 0]
[1, 2, 3, 4, 5, 6]
[[I@11d0a4f