EL expressions are always used within curly braces, and prefixed with a dollar($) sign and $(expression). The first named variable in the expression is either an implicit object or an attribute stored in one of the the four scopes i.e. page, request, session, or application. The [] operator is much more powerful than the dot, because it lets you access Map key or a bean property name as well as the access to arrays and Lists.
An array is a type of container which can hold a fixed number of values of a single type. Array is a collection of similar data types. It means if you have declared an array as string then it can only store the string values. The length of an array is established when an array is created. After creation of the length, its length can't be changed. The [] operator of EL provides us to access the variables of the arrays which dot(.) operator doesn't provide. By using the dot(.) operator we can only access the properties of bean and map.
The code of the program is given below:
| <% String[] name =
{"Hello", "you", "are",
"using", "[] operator", "in",
"EL"}; request.setAttribute("name", name); %> <body> <center> <table> <tr><td><b>The first element is an array is :</td></b> <td><b>${name[0]}</tr></td></b><br> <tr><td><b>The second element is an array is : </td></b> <td><b>${name["1"]}</tr></td></b><br> <tr><td><b>The third element is an array is : </td></b> <td><b>${name["2"]}</tr></td></b><br> <tr><td><b>The fourth element is an array is : </td></b> <td><b>${name["3"]}</tr></td></b><br> <tr><td><b>The fifth element is an array is : </td></b> <td><b>${name["4"]}</tr></td></b><br> <tr><td><b>The sixth element is an array is : </td></b> <td><b>${name["5"]}</tr></td></b><br> <tr><td><b>The seventh element is an array is : </td></b> <td><b>${name["6"]}</tr></td></b><br> </table> </center> </body> |
The output of the program is given below:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Using [] operator of EL with an Array
Post your Comment