String Concatenation
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 concatenating strings using concat method of SpEL.
package com.bethecoder.tutorials.spring3.tests.spel;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class StringConcatTest {
/**
* @param args
*/
public static void main ( String [] args ) {
ExpressionParser parser = new SpelExpressionParser () ;
Expression exp = parser.parseExpression ( "'BTC'.concat(' BTC')" ) ;
String message = exp.getValue ( String. class ) ;
System.out.println ( message ) ;
exp = parser.parseExpression ( "'BTC'.concat(' BTC').concat(' BTC')" ) ;
message = exp.getValue ( String. class ) ;
System.out.println ( message ) ;
}
}
It gives the following output,
BTC BTC
BTC BTC BTC