• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt on usage of dot operator in EL

 
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is it true that anywhere the .(dot) operator is used, the [] could be used instead?
With regards,
Padma priya N.G.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
expr-a.identifier-b is equivalent to expr-a["identifier-b"]
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can you please elaborate this?
With regards,
Padma priya N.G.
 
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Priya,

You can use . operator instead of [] only for Maps and beans. Not for arrays and lists.

For arrays and lists, you have only [] operator.

See, array and list are indexed by integers.
And for them writing
${arrayName.1} will give you an error. Because 1 is not a valid variable name as per Java convention (Any variable name can't be started with number)

However writing ${arrayName[1]} or ${arrayName["1"]} or ${arrayName['1']} will solve the purpose.

One of the main benefit of EL is that , you can have those identifiers as a variable name which are not permitted by Java standards.

And please keep in mind
You can use . operator instead of [] only for Maps and beans. Not for arrays and lists.

Regards,
Khushhal
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but the original question was

------------------------
Is it true that anywhere the .(dot) operator is used, the [] could be used instead?
------------------------

and the answer is "yes"

The reverse is not true for reasons that have been discussed previously

I assume you have asked because this is a typical question asked on mock exams
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Thanks.
With regards,
Padma priya N.G.
reply
    Bookmark Topic Watch Topic
  • New Topic