Home Jsp Simple-jsp-example Declaring string array
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Declaring string array

Advertisement
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 i

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:

 

 

<HTML>
  <HEAD>
    <TITLE>Declaration of an Array</TITLE>
  </HEAD>
 <BODY>
 <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>
   <tr><td> 
    <%
	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]);       
     %>
	 </td></tr>
	 </table>
  </BODY>
</HTML>

Output of the Program:

 

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 12, 2008

Related Tutorials

Ask Questions?    Discuss: Declaring string array  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
mani
July 28, 2011
jsp

its........very usefull prog...
Aagam Shah
January 25, 2012
String array declaration

can we declare the above string array as:- String[] str = {"January","Feb","Apr","March","May"};
DMCA.com