tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Spring > Expression Language > String Length

String Length 

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 getting the length of a string and byte array using SpEL.

File Name  :  
com/bethecoder/tutorials/spring3/tests/spel/StringLengthTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
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 StringLengthTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    ExpressionParser parser = new SpelExpressionParser();
    Expression exp = parser.parseExpression("'BTC'.length()");
    Integer length = exp.getValue(Integer.class);
    System.out.println("String length : " + length);

    exp = parser.parseExpression("'BTC'.bytes.length");
    length = exp.getValue(Integer.class);
    System.out.println("Byte Array length : " + length);
  }

}
   

It gives the following output,
String length : 3
Byte Array length : 3



 
  


  
bl  br