Page 1 of 1

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

Posted: Wed May 14, 2014 1:39 pm
by vchhang
According to the explanation as I understand it, option#3 is correct but yet it is not. Please explain.

Except:
size() method of ArrayList returns the number of elements. Here, it returns 2. Since numbering in ArrayList starts with 0. al.get(2) will cause an IndexOutOfBoundsException to be thrown because only 0 and 1 are valid indexes for a list of size 2.

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

Posted: Wed May 14, 2014 9:09 pm
by admin
It seems to be because of the same repaint problem that you reported earlier. Please see attached image.

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

Posted: Thu Oct 12, 2017 2:27 am
by JuergGogo

Code: Select all

ArrayList<String> al = new ArrayList<String>();
This ArrayList can be declared also like: ArrayList<String> al = new ArrayList<>();

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

Posted: Thu Oct 12, 2017 3:08 am
by admin
JuergGogo wrote:

Code: Select all

ArrayList<String> al = new ArrayList<String>();
This ArrayList can be declared also like: ArrayList<String> al = new ArrayList<>();
Yes, it can be.