[an error occurred while processing this directive]

Declaring string array


An array is the collection of same data type. Suppose if we have a declare an array of type String, then it will store only the String value not any other data type. When we have a closely related data of the same type and scope, it is better to declare it in an array. 

In this example we have declared an array of  type String inside the scriptlet directive. The output will be displayed by using the out implicit object which is provided to us by jsp to display the message on the browser. 

The code of the program is given below:



    <TITLE>Declaration of an Array</TITLE>
 <FONT SIZE="6" COLOR="#660000">Declaration of an Array</FONT>
 <table align="center" bgcolor="#CCFFFF" border="1">
 <tr><td><H3>Declaration of an Array</H3></td></tr>
	String weeks_days[] = new String[7];
	weeks_days[0] = "Sunday";
	weeks_days[1] = "Monday";
	weeks_days[2] =	"Tuesday";
	weeks_days[3] =	"Wednesday";
	weeks_days[4] = "Thursday";
	weeks_days[5] =	"Friday";
	weeks_days[6] =	"Saturday";
	out.println(" " + weeks_days[1]);
	out.println("<br>" + weeks_days[2]);
	out.println("<br> " + weeks_days[3]);
	out.println("<br> " + weeks_days[4]);
	out.println("<br> " + weeks_days[5]);
	out.println("<br>" + weeks_days[6]);
	out.println("<br>Sunday is a holiday " + weeks_days[0]);

Output of the Program:


Download this example.


[an error occurred while processing this directive]