File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ 1st edition, help me understand this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ 1st edition, help me understand this" Watch "HFSJ 1st edition, help me understand this" New topic
Author

HFSJ 1st edition, help me understand this

Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189
At page 428 question 7 in this book it's said that

${foo["5"]} is valid syntax if foo is a Map

I thought that we can use indexes only for lists and arrays ?

am I right ?

SCJP 5 (76%)
SCWCD 5 (86%)
SCBCD 5(70%)
--------------------
"The greatest glory in living lies not in never falling, but in raising every time we fall.".. Nelson Mandela
Vishal Chugh
Ranch Hand

Joined: Oct 27, 2007
Posts: 177
Hi ,

Given if foo is a map:

1) ${foo["5"]} is valid syntax , here 5 will be a key into map.

2) ${foo.5} is not a valid syntax as whatever comes after dot must follow the identfier rules (as per HFSJ)

[See , maps and beans can use dot as well as [] operator (given whatever comes after dot must be a valid identifier)
Arrays and lists can only use [] operator , as indices will always be numerals and wont work with dot ]


You are right : For sure , we have numerals(as indices) with lists and arrays only but we can have numerals as keys in maps too but they will be accessed only using [] , not dot .

I hope , it makes sense.


Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189
Thanks Vishal,

it makes sens
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFSJ 1st edition, help me understand this