JSTL fn:join() and fn:split() function

JSTL fn:join():

The JSTL fn:join() function concatenates the all array elements with a specified separator.
Syntax:

String join (String[] inputArray, String separator)

JSTL fn:split():

The JSTL fn:split() function splits the given string into an array of substrings based on the specified delimiter string.
Syntax:

String[] split(String givenString, String specifiedDelimiter)

Example:

test.jsp

<%@ 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>fn:split and fn:join JSTL function example</title>
	</head>
	<body>
		<c:set var="testString" 
                          value="Hello this is a JSTL function example."/>
		String before splitting: <br/>
		<c:out value="${testString}" />
		<c:set var="testStringAfterSplitting" 
                              value="${fn:split(testString, ' ')}"/><br/>
		<c:set var="testStringAfterJoining" 
                 value="${fn:join(testStringAfterSplitting, '-')}"/><br/>
		String after split and join operation:<br/>	 
		<c:out value="${testStringAfterJoining}" />
	</body>
</html>

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>

Output:

jsp example 58
 
Download this example.
 
Next Topic: JSTL fn:length() function with example.
Previous Topic: JSTL fn:indexOf() function with example.