Error on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 333

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
javiut
Posts: 37
Joined: Fri Oct 19, 2012 10:48 am
Contact:

Error on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 333

Post by javiut »

States that the index must be between 0 and list size inclusive but this is not true.
  • final List<String>myKidName = Arrays.asList("JOHN","STEPHEN","ORTIZ","RONDON");
    System.out.println(myKidName.get(0)+" "+myKidName.get(myKidName.size()));
This is throwing

Code: Select all

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
	at java.util.Arrays$ArrayList.get(Arrays.java:3841)
Because the size is in range [0..3] and the size inclusive is not true must be inclusive and exclusive :thumbup:

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Error on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 333

Post by admin »

The complete sentence that I see is, "Remember that for the get and the remove methods, the index must be between 0 and the
list’s size1 minus 1 (both inclusive)." (There is a typo size1)
This is correct. size minus 1 is indeed inclusive.

javiut
Posts: 37
Joined: Fri Oct 19, 2012 10:48 am
Contact:

Re: Error on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 333

Post by javiut »

i mean this line.

The index value must lie between 0 and list current size (Both inclusive) otherwise an Index just after the 13 for each paragraph.

The index always must be between 0 and list.size()-1 not only for get and remove methods but for all the methods which is a index is passed as parameters except the indexOf this is throwing exception as well you can see is a set method.
final List<String>myKidName = Arrays.asList("JOHN","STEPHEN","ORTIZ","RONDON");
System.out.println(myKidName.set(myKidName.size(),"LA ESTRELLA"));
But this is not throwing any.

Code: Select all

        final List<String>myKidName = Arrays.asList("JOHN","STEPHEN","ORTIZ","RONDON");
        System.out.println("myKidName = " + myKidName.indexOf(Integer.MAX_VALUE));
Last edited by javiut on Sun Mar 01, 2020 10:23 am, edited 1 time in total.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Error on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 333

Post by admin »

I am not able to find this line so may be it has already been fixed.

javiut
Posts: 37
Joined: Fri Oct 19, 2012 10:48 am
Contact:

Re: Error on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 333

Post by javiut »

Yes may be i have the october version :( hehehe. did you as the author about the country name stuff?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Error on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 333

Post by admin »

Yes. We will add country for all of the readers mentioned on the ack page may be in the next version.

javiut
Posts: 37
Joined: Fri Oct 19, 2012 10:48 am
Contact:

Re: Error on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 333

Post by javiut »

awesome man thanks remember Venezuela is my country :) which number version will be the next?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Error on OCP 1Z0-815 BOOK Deshmukh, Hanumant Page 333

Post by admin »

I am unable to comment on the exact build number it will be there but it will be there.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests