A brief in JSP Array !
JSP does not have array structure as JSP is not a complete programming language. JSP doesn't have array structure but array are declared using Java can be used in JSP. In JSP arrays are used to storeseveral data types in a series that can be string,int,dynamic data, vector etc.
Single Dimension Array:
Single dimensional array is a list of variables of same type that are
accessed by a common name. An individual variable in the array is called
an array element. Arrays forms a way to handle groups of related data.
JSP File (index.jsp)
<!DOCTYPE html>
<html>
<head>
<title>nirajanghimireyworkshop.blogspot.com</title>
</head>
<body>
<%
double arr[];
arr = new double[100];
arr[5] = 4.5;
out.println("Array index [3] holds " + arr[5]);
%>
</body>
</html>
Multi Dimensional Array:
In Java, multidimensional arrays are actually arrays of
arrays. These, as you might expect, look and act like regular multidimensional
arrays. However, as you will see, there are a couple of subtle
differences.
JSP File (index.jsp)
<!DOCTYPE html>
<html>
<head>
<title>nirajanghimireyworkshop.blogspot.com</title>
</head>
<body>
<%
double arr[][] = new double[2][10];
arr[0][1] = 19.3;
arr[1][2] = 45.02;
out.println("Array index [0][1] holds " + arr[0][1] + "<br/>");
out.println("Array index [1][2] holds " + arr[1][2]);
%>
</body>
</html>
No comments:
Post a Comment