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.
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?
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.
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 ?