Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.779 :

Posted: Tue Jul 24, 2012 6:19 am
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.

Re: About Question com.enthuware.ets.scjp.v6.2.779 :

Posted: Tue Jul 24, 2012 8:21 pm
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.