How can the return type be a List if List is an interface?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.
[HD Pg 356, Sec. 12.4.2 - arraylist-api]
Moderator: admin
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
[HD Pg 356, Sec. 12.4.2 - arraylist-api]
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 356, Sec. 12.4.2 - arraylist-api]
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.
-
- Posts: 26
- Joined: Wed Oct 02, 2019 1:42 pm
- Contact:
Re: [HD Pg 356, Sec. 12.4.2 - arraylist-api]
Wouldn't it be inclusive for 0, and exclusive for the size?The index value must lie between 0 and the list's current size (both inclusive)
[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.
This in Kindle Cloud Reader, in Google Chrome.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 356, Sec. 12.4.2 - arraylist-api]
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!
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.
Who is online
Users browsing this forum: No registered users and 103 guests