About Question enthuware.ocajp.i.v7.2.851 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
Kevin_C
Posts: 14
Joined: Mon Nov 03, 2014 5:18 am
Contact:

About Question enthuware.ocajp.i.v7.2.851 :

Post by Kevin_C »

I had the answer correct, but I was wondering about the answer:
ArrayList cannot resize dynamically if you add more number of elements than its capacity.

ArrayList also got a max-sized constructor, right?

Code: Select all

ArrayList<Integer> l = new ArrayList<>(5); // <- ArrayList of size 5 (array behind the scenes with length 5)

// So I can't do:
for(int i = 0; i < 6; i++)
      l.add(i); // For element 6 it will throw an IndexOutOfBoundsException (or ArrayIndexOutOfBoundsException?)
The only reason I can see when you want a max-sized ArrayList is when you don't want default values like with a max-sized array. Probably the reason why it's added. :)

Harini
Posts: 2
Joined: Fri Feb 20, 2015 2:12 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.851 :

Post by Harini »

Hi,

for this question, one of the options says "You cannot store primitives in an ArrayList."

If my understanding is correct, primitives are int, short , long etc. And am able to add them to an ArrayList. So how does the above statement hold true ?

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

Re: About Question enthuware.ocajp.i.v7.2.851 :

Post by admin »

Primitives are actually wrapped into wrapper objects and those wrapper objects (not primitives) are stored in the list.
If you like our products and services, please help us by posting your review here.

sahilsaid
Posts: 5
Joined: Tue Oct 11, 2016 4:41 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.851 :

Post by sahilsaid »

I think the following option needs to be changed to make things clear.

"You cannot store primitives in an ArrayList."

Should be changed to something similar.

"You cannot store primitives directly (or as it is) in an ArrayList."

I though the option is saying that it is impossible to store the primitives in the arrayList.

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

Re: About Question enthuware.ocajp.i.v7.2.851 :

Post by admin »

It IS impossible to store primitives in a List. Wrappers are not primitives.
If you like our products and services, please help us by posting your review here.

sahilsaid
Posts: 5
Joined: Tue Oct 11, 2016 4:41 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.851 :

Post by sahilsaid »

I am not saying that primitives are wrappers but that option made me think that it is asking whether the following is possible or not in arraylist.

List a = new ArrayList();
a.add(1); //compile error according to that option maybe? but works fine of course.

It was only a suggestion from me to improve the option.

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

Re: About Question enthuware.ocajp.i.v7.2.851 :

Post by admin »

Ok, I see your point. Will make it more clear.
thank you for your feedback.
-Paul.
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 15 guests