[HD Pg 366, Sec. 12.4.3 - disadvantages-of-arraylist]

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

Moderator: admin

Post Reply
enthunoob
Posts: 60
Joined: Thu Apr 15, 2021 12:21 pm
Contact:

[HD Pg 366, Sec. 12.4.3 - disadvantages-of-arraylist]

Post by enthunoob »

As written on page 88 as well, that Arraylist (autoboxes stored primitives cause it) only works with objects, what causes this? Why does ArrayList only work with objects?/Why do simple Arrays allow primitives?

But later it might have dawned on me: cause all of the arguments of ArrayList-methods are generic-types. Please verify

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

Re: [HD Pg 366, Sec. 12.4.3 - disadvantages-of-arraylist]

Post by admin »

ArrayList is like any other class written by an application programmer. It doesn't work with primitives because it is not designed by the class designers that way. They designed it to work with objects only.

It is a design decision taken most likely because it uses an Object array as the internal data structure and you can't store primitives in an array of objects and the didn't think that ArrayList of primitives would be very useful. (Please note that this is my guess only.)
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 70 guests