fn:join() JSTL Function

fn:join() JSTL Function Example explains about How to Join all elements of an array into a string.

Consider an example string where you need to convert all the elements of an array into string.

fn:join() JSTL Functiion will used to combine / merge every elements of a particular array into a string.

java.lang.String join(java.lang.String[], java.lang.String)

You can see the below example, which is demonstrating fn:join() JSTL Function 

Required Libraries

You need to download

  1. Tomcat 9
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

fn:join() Example

<%@ 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:join</title>
</head>
<body>
  
<%
   // you can also set the values into request scope same as using c:set
   // request.setAttribute("str", "Testing a String");
%>

<c:set var="str" value="Testing a String" /> 

<c:set var="array" value="${fn:split(str, ' ')}" /> 

<c:out value="${fn:join(array,'|')}" /> 

</body> 
</html>
Output
Testing|a|String

 











2 Responses to "fn:join() JSTL Function"
  1. Rocker 2011-12-26 08:06:35.0
  1. admin 2011-12-27 08:06:35.0

Your email address will not be published. Required fields are marked *