Entry
JSP - arrays
May 13th, 2008 20:57
dman, i can do it, Praveen sehrawat, mehul parikh, http://sturly.com
JSP Array
JSP Array and Variable
Program data can be store in variables. Each variable has a type, and
a scope. The most common data structure is the array. Arrays are
fixed length structures for storing multiple values. .Object so an
array is an instance of Object. arrays support directly language
features. It means that their performance is on par with primitives
and that they have a unique syntax that is different than objects
Structure of Java Array
The Java array has 7 elements. Each element holds a distinct value in
array. Elements are always referenced by their indices. The first
element is always index 0. this zero-based numbering, the last element
array in the index is always the array's length minus one. for
example :- the last element can be index 7 because 8 minus 1 equals 7.
Declaration and Initialization of Java Arrays
Java array variable is declared the same process as Java variable is
declared. the array elements are [] notation is used to denote that
the variable is an array. Once an array variable has been declared,
memory allocated to array. This is done with the new operator, which
allocates memory for objects. The new operator is followed by the
type, the number of elements to allocate. The number of elements to
allocate is placed within the [] operator.
LOOP DEMO
static final String[] COLOR =
{ "#CA9A26", "#3BF428", "#F7E339", "#FF40FF", };
%>
<%
for (int i = 0; i < COLOR.length; i++) {
String color = COLORS[i];
%>
<div style="background-color: <%= color%>;
font-size: 12pt;
font-weight: bold;">
This is color <%= color %>
</div>
<% } %>