129k views
2 votes
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();

1 Answer

3 votes

Answer:

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

Step-by-step 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<>();

User Gomad
by
5.0k points