23.2k views
4 votes
Which of the following does not correctly declare an ArrayList?

a. ArrayList‹Integer› list = new ArrayList‹Integer›(10)
b. ArrayList‹Integer› = new ArrayList‹Integer›(10)
c. ArrayList‹Integer› list = new ArrayList‹Integer›()

1 Answer

6 votes

Answer:

Option b. ArrayList‹Integer› = new ArrayList‹Integer›(10) does not correctly declare an ArrayList.

Step-by-step explanation:

ArrayList in Java dynamically stores elements in it. It also called as re- sizeable array as it expands in size when elements are added and decreases when an element is removed from it. This array list class also allows to use duplicate and null values.

The syntax for creating Array list is as follows

ArrayList<Type> obj = new ArrayList<Type>()

Type specifies the type of ArrayList like Integer, Character, Boolean etc, and obj is the object name. But in the option b ArrayList‹Integer› = new ArrayList‹Integer›(10) object name is missed and not specified.

User Ioannis
by
6.1k points