To create a list to store integers, use:________

a. ArrayList list = new ArrayList();
b. ArrayList list = new ArrayList();
c. ArrayList list = new ArrayList();
d. ArrayList list = new ArrayList();

Answer :

MrRoyal

Answer:

ArrayList<Integer> list = new ArrayList<>();

Explanation:

From the list of given options a to d

ArrayList represents the list name

Also, the syntax is similar to java programming language. Hence, I'll answer this question base on the syntax of Java programming language.

In java, the syntax to declare a list is

[Variable-name]<list-type> list = [Variable-name]<list-type>();

Replace [Varable-name] with ArrayList

ArrayList<list-type> list = ArrayList<list-type>();

From the question, the list is meant to store integers;

So, replace list-type with integer...

This gives

ArrayList<Integer> list = new ArrayList<>();

Other Questions