Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
Moderator: admin
-
ETS User
Post
by ETS User »
Code: Select all
if public int getLen(List al )
{
if( al != null) return ( (String) al.get(0)).length();
else return 0;
}
There could be a NPE if the given list has no elements.
-
admin
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
-
Contact:
Post
by admin »
Actually, it will throw an IndexOutOfBoundsException if the given list has no elements. It will throw NPE if al is null.
However, both are irrelevant to the question.
HTH,
Paul.
If you like our products and services, please help us by posting your
review here.
Users browsing this forum: Bing [Bot] and 208 guests