The JSTL function fn:length() is used for computing the length of a string or to find out the number of elements in a collection.
Syntax
int length(Object)
Return type of this function is int. It returns the length of the object provided in it as an argument.
Example of fn:length()
Here we are computing the length of the three different strings using the function.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <html> <head> <title>JSTL fn:length() example</title> </head> <body> <c:set var="string1" value="This is String1"/> <c:set var="string2" value="Hi"/> <c:set var="string3" value="string3"/> Length of String1 is: ${fn:length(string1)}<br> Length of String2 is: ${fn:length(string2)}<br> Length of String3 is: ${fn:length(string3)} </body> </html>
Output:
Leave a Reply