[HD Pg 356, Sec. 12.4.2 - arraylist-api]

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

Moderator: admin

Post Reply
flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

[HD Pg 356, Sec. 12.4.2 - arraylist-api]

Post by flex567 »

Observe that the type of the variables in the above code is List and not ArrayList. This is because the return type of asList is List. Although you will not be tested on this method in the exam, you may see code that uses this method to build an ArrayList with a few elements in a single statement.
How can the return type be a List if List is an interface?

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

Re: [HD Pg 356, Sec. 12.4.2 - arraylist-api]

Post by admin »

Because an interface is also a type. See 1.1.3 Type, class, enum, and interface.
If you like our products and services, please help us by posting your review here.

DazedTurtle
Posts: 26
Joined: Wed Oct 02, 2019 1:42 pm
Contact:

Re: [HD Pg 356, Sec. 12.4.2 - arraylist-api]

Post by DazedTurtle »

The index value must lie between 0 and the list's current size (both inclusive)
Wouldn't it be inclusive for 0, and exclusive for the size?

[1, 2, 3] would have size 3, right? So if the index must be between 0 and the size, both inclusive, then that would make 0, 1, 2, and 3 valid indices. But 3 would be out of bounds, wouldn't it?

Edit: Also, something seems to be off about the character encoding? Here's a screenshot, since it has weird characters and I can't copy and paste.
studyGuideEncoding.png
studyGuideEncoding.png (29.5 KiB) Viewed 1162 times
This in Kindle Cloud Reader, in Google Chrome.

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

Re: [HD Pg 356, Sec. 12.4.2 - arraylist-api]

Post by admin »

1. Actually that text is about the add method but it is not mentioned so. It will be improved.
2. The junk characters should be removed.

thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 44 guests